Skip to content

feat(parsing): handle user parsing error#38

Open
axel7083 wants to merge 1 commit intoSdju:masterfrom
axel7083:feature/handle-autotype-errors
Open

feat(parsing): handle user parsing error#38
axel7083 wants to merge 1 commit intoSdju:masterfrom
axel7083:feature/handle-autotype-errors

Conversation

@axel7083
Copy link
Contributor

@axel7083 axel7083 commented Mar 4, 2025

Description

As per documentation, we can define a autoTyping with the following

import { parse } from 'js-ini';

const ACCEPTED = ['hello', 'world'];

const content = parse(<string>, {
  autoTyping: (val, section, key) => {
    if (key in ACCEPTED) return val;
    throw new Error(`key ${key} is not valid in section ${section}`);
  },
});

It can be useful to throw an error in this function to ensure the type safety of the content parsed. But above all, when parsing the ParsingError is very valuable as it contains lineNumber information.

Wrapping the user error in a ParsingError improving the parsing capabilities.

Background

I am writing a Language Service for a specific format derived from the .ini, and having a nice way to collect all parsing error is very valuable.

cc @Sdju

Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
@axel7083 axel7083 force-pushed the feature/handle-autotype-errors branch from 7baf20b to b54ae75 Compare March 4, 2025 13:21
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.

1 participant

Comments