danixeee: @Maxattax97 thank you for your contribution! I will review it shortly.

Please take a look at [contributing](https://github.com/openlawlibrary/pygls/blob/master/CONTRIBUTING.md) document, section [Final Checklist](https://github.com/openlawlibrary/pygls/blob/master/CONTRIBUTING.md#final-checklist). 
Maxattax97: I've updated my original comment, added your proposed changes, and including documentation where needed in markdown files.

Let me know if there's anything else to be done!
Maxattax97: Can't say I understand why the CI failed?
Maxattax97: I'm relatively new to Python and still learning some of it's development workflow, thanks for your patience :smile:. I didn't know you could locally install like that (`pip3 install .`) into a venv, good to know from now on.

This is also my first in-depth code review. I've made PR's before, but never had the opportunity to really go through the process, so this is good :+1:.
dgreisen: @Maxattax97 Thanks for your contribution. When your OpenSCAD languange server is up, we'd love if you added it to https://github.com/openlawlibrary/pygls/blob/master/Implementations.md.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a1d2aa1..7a894cc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning][semver].
 
 ## [Unreleased]
 
+### Changed
+
+- Fix initialization failure when no workspace is open
+
 ## [0.7.3] - 01/30/2019
 
 ### Added
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index 18388fd..48307c3 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -2,4 +2,5 @@
 
 - [@augb](https://github.com/augb)
 - [Daniel Elero](https://github.com/danixeee)
+- [Max O'Cull](https://github.com/Maxattax97)
 - [yorodm](https://github.com/yorodm)
diff --git a/pygls/exceptions.py b/pygls/exceptions.py
index de276c1..8d2823e 100644
--- a/pygls/exceptions.py
+++ b/pygls/exceptions.py
@@ -56,7 +56,7 @@ class JsonRpcException(Exception):
             'message': self.message,
         }
         if self.data is not None:
-            exception_dict['data'] = self.data
+            exception_dict['data'] = str(self.data)
         return exception_dict
 
 
diff --git a/pygls/protocol.py b/pygls/protocol.py
index affcb02..c065d7d 100644
--- a/pygls/protocol.py
+++ b/pygls/protocol.py
@@ -526,11 +526,8 @@ class LanguageServerProtocol(JsonRPCProtocol, metaclass=LSPMeta):
         root_uri = params.rootUri or from_fs_path(root_path)
 
         # Initialize the workspace
-        self.workspace = Workspace(root_uri, self)
-
         workspace_folders = getattr(params, 'workspaceFolders', [])
-        for folder in workspace_folders:
-            self.workspace.add_folder(folder)
+        self.workspace = Workspace(root_uri, workspace_folders)
 
         return InitializeResult(server_capabilities)
 
diff --git a/pygls/workspace.py b/pygls/workspace.py
index b13193c..8a7f5a4 100644
--- a/pygls/workspace.py
+++ b/pygls/workspace.py
@@ -128,14 +128,17 @@ class Document(object):
 
 class Workspace(object):
 
-    def __init__(self, root_uri, lsp):
+    def __init__(self, root_uri, workspace_folders=None):
         self._root_uri = root_uri
-        self._lsp = lsp
         self._root_uri_scheme = uri_scheme(self._root_uri)
         self._root_path = to_fs_path(self._root_uri)
         self._folders = {}
         self._docs = {}
 
+        if workspace_folders is not None:
+            for folder in workspace_folders:
+                self.add_folder(folder)
+
     def _create_document(self,
                          doc_uri: str,
                          source: str = None,

Message: TypeError: 'NoneType' object is not iterable
I'd like to use this to build an LSP for a small language called OpenSCAD, so I started investigating this project (excellent code and docs by the way!). I'm normally a Neovim user, but for sake of better understanding pygls, I installed VS code (in other words, might just be a configuration error) and ran the example JSON language server in debug mode. Unfortunately, I'm quickly met with this error in the debug client running alongside the server:
```
[Error - 12:11:01 AM] Server initialization failed.
  Message: TypeError: 'NoneType' object is not iterable
  Code: -32602 
[object Object]
```

Any ideas on how I could get around this? Is this a new error, or is it a common bump in the road?

Thanks in advance.
diff --git a/tests/conftest.py b/tests/conftest.py
index ebb6698..1ef4cc9 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -21,7 +21,6 @@ import os
 from threading import Thread
 
 import pytest
-from mock import Mock
 from pygls import features, uris
 from pygls.feature_manager import FeatureManager
 from pygls.server import LanguageServer
@@ -91,4 +90,4 @@ def feature_manager():
 @pytest.fixture
 def workspace(tmpdir):
     """Return a workspace."""
-    return Workspace(uris.from_fs_path(str(tmpdir)), Mock())
+    return Workspace(uris.from_fs_path(str(tmpdir)))
diff --git a/tests/test_workspace.py b/tests/test_workspace.py
index 549a082..c6c122b 100644
--- a/tests/test_workspace.py
+++ b/tests/test_workspace.py
@@ -19,9 +19,9 @@
 import os
 
 from pygls import uris
+from pygls.workspace import Workspace
 from pygls.types import TextDocumentItem, WorkspaceFolder
 
-
 DOC_URI = uris.from_fs_path(__file__)
 DOC_TEXT = '''test'''
 DOC = TextDocumentItem(DOC_URI, 'plaintext', 0, DOC_TEXT)
@@ -66,3 +66,13 @@ def test_remove_document(workspace):
     assert workspace.get_document(DOC_URI).source == DOC_TEXT
     workspace.remove_document(DOC_URI)
     assert workspace.get_document(DOC_URI)._source is None
+
+
+def test_workspace_folders():
+    wf1 = WorkspaceFolder('/ws/f1', 'ws1')
+    wf2 = WorkspaceFolder('/ws/f2', 'ws2')
+
+    workspace = Workspace('/ws', [wf1, wf2])
+
+    assert workspace.folders['/ws/f1'] is wf1
+    assert workspace.folders['/ws/f2'] is wf2

pip install -e .[dev]
parse_log_pytest
pytest
pytest flake8 bandit
apt-get update apt-get install -y gcc
3.9
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
bandit==1.5.1
entrypoints==0.3
exceptiongroup @ file:///croot/exceptiongroup_1706031385326/work
flake8==3.7.1
gitdb==4.0.12
GitPython==3.1.44
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
markdown-it-py==3.0.0
mccabe==0.6.1
mdurl==0.1.2
packaging @ file:///croot/packaging_1734472117206/work
pbr==6.1.1
pluggy @ file:///croot/pluggy_1733169602837/work
pycodestyle==2.5.0
pyflakes==2.1.1
-e git+https://github.com/openlawlibrary/pygls.git@3c5433648d278cc72b3b5ecf50ca0b73c57b2f75#egg=pygls
Pygments==2.19.1
pytest @ file:///croot/pytest_1738938843180/work
PyYAML==6.0.2
rich==14.0.0
six==1.17.0
smmap==5.0.2
stevedore==5.4.1
tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work
typing_extensions==4.13.0

name: pygls
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - exceptiongroup=1.2.0=py39h06a4308_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - packaging=24.2=py39h06a4308_0
  - pip=25.0=py39h06a4308_0
  - pluggy=1.5.0=py39h06a4308_0
  - pytest=8.3.4=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tomli=2.0.1=py39h06a4308_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - bandit==1.5.1
      - entrypoints==0.3
      - flake8==3.7.1
      - gitdb==4.0.12
      - gitpython==3.1.44
      - markdown-it-py==3.0.0
      - mccabe==0.6.1
      - mdurl==0.1.2
      - pbr==6.1.1
      - pycodestyle==2.5.0
      - pyflakes==2.1.1
      - pygments==2.19.1
      - pyyaml==6.0.2
      - rich==14.0.0
      - six==1.17.0
      - smmap==5.0.2
      - stevedore==5.4.1
      - typing-extensions==4.13.0
prefix: /opt/conda/envs/pygls

tests/test_workspace.py::test_add_folder tests/test_workspace.py::test_get_document tests/test_workspace.py::test_get_missing_document tests/test_workspace.py::test_put_document tests/test_workspace.py::test_remove_folder tests/test_workspace.py::test_remove_document tests/test_workspace.py::test_workspace_folders
CONTRIBUTORS.md CHANGELOG.md pygls/exceptions.py pygls/protocol.py pygls/workspace.py
CONTRIBUTORS.md CHANGELOG.md pygls/exceptions.py pygls/protocol.py pygls/workspace.py