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

Better error messages when importing an unavailable .ksy #161

Merged
merged 4 commits into from
Jan 21, 2024

Conversation

generalmimon
Copy link
Member

@generalmimon generalmimon commented Dec 6, 2023

For example, consider the following spec, which attempts to import a non-existent .ksy file from local storage:

meta:
  id: imports_non_existent_local
  imports:
    - non_existent

Old error:

Parse error (TypeError): Cannot read properties of null (reading 'indexOf')
Call stack: TypeError: Cannot read properties of null (reading 'indexOf')
    at Parser.cleanup (https://ide.kaitai.io/lib/_npm/yamljs/yaml.js:1220:15)
    at Parser.parse (https://ide.kaitai.io/lib/_npm/yamljs/yaml.js:754:23)
    at Yaml.parse (https://ide.kaitai.io/lib/_npm/yamljs/yaml.js:1817:25)
    at JsImporter.importYaml (https://ide.kaitai.io/js/v1/KaitaiServices.js:51:33)

New error:

(main): /meta/imports/0:
	error: failed to import spec non_existent.ksy from local storage: file not found

Import failures from the remote location "kaitai.io" are now also handled - consider this spec:

meta:
  id: imports_non_existent_remote
  imports:
    - /common/non_existent

Old error:

Parse error
Call stack: undefined

New error:

(main): /meta/imports/0:
	error: failed to import spec formats/common/non_existent.ksy from kaitai.io: file not found

When the server responds with some other HTTP status code than 404:

(main): /meta/imports/0:
	error: failed to import spec formats/common/bcd.ksy from kaitai.io: server responded with HTTP status 500 (Internal Server Error)

When you are no longer connected to the internet, but try to import a remote spec that hasn't been cached locally by the browser:

(main): /meta/imports/0:
	error: failed to import spec formats/common/bcd.ksy from kaitai.io: cannot reach the server (message: Failed to fetch), check your internet connection

Copy link
Member

@GreyCat GreyCat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for implementing this! Looks great to me!

For example, consider the following spec, which attempts to import a
non-existent .ksy file from local storage:

```ksy
meta:
  id: imports_non_existent_local
  imports:
    - non_existent
```

Old error:

```
Parse error (TypeError): Cannot read properties of null (reading 'indexOf')
Call stack: TypeError: Cannot read properties of null (reading 'indexOf')
    at Parser.cleanup (https://ide.kaitai.io/lib/_npm/yamljs/yaml.js:1220:15)
    at Parser.parse (https://ide.kaitai.io/lib/_npm/yamljs/yaml.js:754:23)
    at Yaml.parse (https://ide.kaitai.io/lib/_npm/yamljs/yaml.js:1817:25)
    at JsImporter.importYaml (https://ide.kaitai.io/js/v1/KaitaiServices.js:51:33)
```

New error:

```
(main): /meta/imports/0:
	error: Error: failed to import spec non_existent.ksy from local storage: file not found
```

Import failures from the remote location "kaitai.io" are now also
handled - consider this spec:

```ksy
meta:
  id: imports_non_existent_remote
  imports:
    - /common/non_existent
```

Old error:

```
Parse error
Call stack: undefined
```

New error:

```
(main): /meta/imports/0:
	error: Error: failed to import spec formats/common/non_existent.ksy from kaitai.io: file not found
```

When the server responds with some other HTTP status code than 404:

```
(main): /meta/imports/0:
	error: Error: failed to import spec formats/common/bcd.ksy from kaitai.io: server responded with HTTP status 500 (Internal Server Error)
```

When you are no longer connected to the internet, but try to import a
remote spec that hasn't been cached locally by the browser:

```
(main): /meta/imports/0:
	error: Error: failed to import spec formats/common/bcd.ksy from kaitai.io: cannot reach the server (message: Failed to fetch), check your internet connection
```
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 this pull request may close these issues.

None yet

2 participants