Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension Error (exception: 'sources') #166

Open
zapfdk opened this issue Jan 11, 2021 · 7 comments · May be fixed by #189
Open

Extension Error (exception: 'sources') #166

zapfdk opened this issue Jan 11, 2021 · 7 comments · May be fixed by #189

Comments

@zapfdk
Copy link

zapfdk commented Jan 11, 2021

Hi,
I'm trying to build Typescript documentation, but I'm getting this error when executing make html SPHINXOPTS=-v (local paths replaced with $env_path for privacy):

Traceback (most recent call last):
  File "$env_path/lib/python3.8/site-packages/sphinx/events.py", line 110, in emit
    results.append(listener.handler(self.app, *args))
  File "$env_path/lib/python3.8/site-packages/sphinx_js/__init__.py", line 60, in analyze
    app._sphinxjs_analyzer = analyzer.from_disk(abs_source_paths,
  File "$env_path/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 40, in from_disk
    return cls(json, base_dir)
  File "$env_path/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 29, in __init__
    ir_objects = self._convert_all_nodes(json)
  File "$env_path/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 113, in _convert_all_nodes
    converted, more_todo = self._convert_node(todo.pop())
  File "$env_path//lib/python3.8/site-packages/sphinx_js/typedoc.py", line 154, in _convert_node
    constructor, members = self._constructor_and_members(node)
  File "$env_path/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 100, in _constructor_and_members
    ir, _ = self._convert_node(child)
  File "$env_path/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 190, in _convert_node
    first_sig['sources'] = node['sources']
KeyError: 'sources'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "$env_path/lib/python3.8/site-packages/sphinx/cmd/build.py", line 276, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
  File "$env_path/lib/python3.8/site-packages/sphinx/application.py", line 278, in __init__
    self._init_builder()
  File "$env_path/lib/python3.8/site-packages/sphinx/application.py", line 337, in _init_builder
    self.events.emit('builder-inited')
  File "$env_path/lib/python3.8/site-packages/sphinx/events.py", line 117, in emit
    raise ExtensionError(__("Handler %r for event %r threw an exception") %
sphinx.errors.ExtensionError: Handler <function analyze at 0x7f0ca88759d0> for event 'builder-inited' threw an exception (exception: 'sources')

Extension error:
Handler <function analyze at 0x7f0ca88759d0> for event 'builder-inited' threw an exception (exception: 'sources')

Versions:
TypeDoc 0.20.14
Using TypeScript 4.1.3 from /usr/lib/node_modules/typescript/lib
Sphinx 3.4.3
Sphinx-js 3.1

I tried debugging, but I'm new to typedoc, so I'm kind of stuck.
What I could tell was that it crashes when processing the constructor of my class, in typedoc.py kind == Constructor

Any idea where this is coming from?

@erikrose
Copy link
Contributor

It sounds like TypeDoc's JSON format has changed again. Can you try on TypeDoc 0.15.0 and see if it works? We're known to be compatible with that version (and working on future versions: see #162).

@zapfdk
Copy link
Author

zapfdk commented Jan 11, 2021

With TypeDoc 0.15.0 (which downgrades Typescript to 3.5.3. and highlight.js to 9.18.5, I receive this error message:


Using TypeScript 3.5.3 from /usr/lib/node_modules/typedoc/node_modules/typescript/lib
Error: $imported_file_path.ts(0)
 Cannot use imports, exports, or module augmentations when '--module' is 'none'.

Traceback (most recent call last):
  File "$env_path/lib/python3.8/site-packages/sphinx/events.py", line 110, in emit
    results.append(listener.handler(self.app, *args))
  File "$env_path/lib/python3.8/site-packages/sphinx_js/__init__.py", line 60, in analyze
    app._sphinxjs_analyzer = analyzer.from_disk(abs_source_paths,
  File "$env_path/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 37, in from_disk
    json = typedoc_output(abs_source_paths,
  File "$env_path/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 331, in typedoc_output
    return load(getreader('utf-8')(temp))
  File "$home_path/.pyenv/versions/3.8.6/lib/python3.8/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "$home_path/.pyenv/versions/3.8.6/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "$home_path/.pyenv/versions/3.8.6/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "$home_path/.pyenv/versions/3.8.6/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "$env_path/lib/python3.8/site-packages/sphinx/cmd/build.py", line 276, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
  File "$env_path/lib/python3.8/site-packages/sphinx/application.py", line 278, in __init__
    self._init_builder()
  File "$env_path/lib/python3.8/site-packages/sphinx/application.py", line 337, in _init_builder
    self.events.emit('builder-inited')
  File "$env_path/lib/python3.8/site-packages/sphinx/events.py", line 117, in emit
    raise ExtensionError(__("Handler %r for event %r threw an exception") %
sphinx.errors.ExtensionError: Handler <function analyze at 0x7f10265c49d0> for event 'builder-inited' threw an exception (exception: Expecting value: line 1 column 1 (char 0))

Extension error:
Handler <function analyze at 0x7f10265c49d0> for event 'builder-inited' threw an exception (exception: Expecting value: line 1 column 1 (char 0))

module is set to "commonjs" in tsconfig.json

In $imported_file_path, I'm importing another library file with import * from "./other_file.js" which again imports * from crypto.

@erikrose
Copy link
Contributor

Well, I don't know what the heck any of that means, but it doesn't look good! :-) Hopefully when we get around to updating for newer versions of typedoc, it'll fix this.

@pretentious7
Copy link

pretentious7 commented Feb 1, 2021

I had this error recently, fixed it by changing

js_source_path = '../../$SRC_FOLDER' to js_source_path = '../../$SRC_FOLDER/$SRC_FILE'

but this of course doesn't seem to work when setting js_source_path to a list of things.

@wolfviking0
Copy link

Hi Guys, regarding this problem I understand where is the issue but not sure the exact way to fix it.

Inside

first_sig['sources'] = node['sources']

the node['sources'] seems to be invalid when the kind is Constructor.

@Gallaecio
Copy link

Minimal, reproducible example with TypeDoc 0.22.15:

$ cat conf.py 
exclude_patterns = [
    'venv',
]
extensions = [
    'sphinx_js',
]
js_language = 'typescript'
js_source_path = '.'
jsdoc_config_path = 'tsconfig.json'
$ cat index.ts 
export class Foo {}
$ cat tsconfig.json 
{"compilerOptions": {"lib": ["dom", "es2018"]}, "entryPoints": ["index.ts"]}
$ touch index.rst
$ python3 -m venv venv
$ . venv/bin/activate
(venv) $ pip install sphinx git+https://github.com/mozilla/sphinx-js.git
…
Successfully installed … sphinx-5.1.1 sphinx-js-3.1.2 …
…
(venv) $ sphinx-build -b html -v . _build
…
Traceback (most recent call last):
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx/events.py", line 94, in emit
    results.append(listener.handler(self.app, *args))
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx_js/__init__.py", line 61, in analyze
    app._sphinxjs_analyzer = analyzer.from_disk(abs_source_paths,
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx_js/typedoc.py", line 41, in from_disk
    return cls(json, base_dir)
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx_js/typedoc.py", line 30, in __init__
    ir_objects = self._convert_all_nodes(json)
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx_js/typedoc.py", line 142, in _convert_all_nodes
    converted, more_todo = self._convert_node(todo.pop())
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx_js/typedoc.py", line 183, in _convert_node
    constructor, members = self._constructor_and_members(node)
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx_js/typedoc.py", line 129, in _constructor_and_members
    ir, _ = self._convert_node(child)
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx_js/typedoc.py", line 219, in _convert_node
    first_sig['sources'] = node['sources']
KeyError: 'sources'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx/cmd/build.py", line 272, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx/application.py", line 261, in __init__
    self._init_builder()
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx/application.py", line 334, in _init_builder
    self.events.emit('builder-inited')
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx/events.py", line 105, in emit
    raise ExtensionError(__("Handler %r for event %r threw an exception") %
sphinx.errors.ExtensionError: Handler <function analyze at 0x7f2e80dd4ee0> for event 'builder-inited' threw an exception (exception: 'sources')

Extension error (sphinx_js):
Handler <function analyze at 0x7f2e80dd4ee0> for event 'builder-inited' threw an exception (exception: 'sources')

@Gallaecio
Copy link

I can get it to work with 0.16.11 (0.17.0 is the breaking point), avoiding #166 (comment), by including module in tsconfig.json.

That is, my minimal example works after the following changes:

  • typedoc 0.22.15 → 0.16.11
  • New content of tsconfig.json: {"compilerOptions": {"lib": ["dom", "es2018"], "module": "ES6"}, "entryPoints": ["index.ts"]}

hoodmane added a commit to hoodmane/sphinx-js that referenced this issue Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants