lc-soft/trad

Friendly error output #4

lc-soft posted onGitHub

Description:

The error message is output using assert, which does not tell the user which line of code is having problems and does not identify what type of error.

The type of error should be identified, for example:

  • SyntaxError
  • ReferenceError
  • TypeError
  • InternalError

Reference:

https://github.com/lc-soft/trad/blob/d4a022e74bd3fcb6b7cf0d6c9fea031ad87b8685/packages/trad-compiler/src/declaration.js#L6-L15

Cost:

1 week ~ 1 month

benefits:

Users will be easier to locate problems

Assignee:

Who do you want to be assignee for this feature?

  • I will implement this feature
  • Other contributors
  • Maintainers
  • I don't know

Contribution:

For this feature, I will provide these contributions:

  • Contribute documentions
  • Contribute testcases
  • Develop other feuatres, or fix existing bugs
  • Write an article to promote this project
  • Fund this issue on IssueHunt
  • Donate this project on OpenCollective
  • I don't want to provide any help

@lc-soft has funded $20.00 to this issue.


posted by issuehunt-app[bot] almost 6 years ago

@lc-soft I would like to take this up. This is my first contribution here. Could you help me more to understand the exact issue.

posted by arshadkazmi42 over 5 years ago

Could you help me more to understand the exact issue.

@arshadkazmi42

The error handling of the compiler needs to be improved. The error object should contain the path, content, line, column of the compiled file.

How to getting started?

To getting started, you should define some custom error classes, for example:

class TradError extends Error {
  // ...
}
class TradTypeError extends TradError {
  // ...
}
class TradSyntaxError extends TradError {
  // ...
}
class TradReferenceError extends TradError {
  // ...
}

How to get path, content, line, column of the compiled file?

For path and content of file, please read this source file: https://github.com/lc-soft/trad/blob/master/packages/trad-compiler/index.js#L129

Maybe you need to write code to store them.

For getting line and column, please read: https://github.com/acornjs/acorn/tree/master/acorn#interface

When locations is true, acorn parser will provide these data, but where is the data and how to get it, you need to solve it.

How to throw these errors?

Search all assert function calls and change them to the throw statement, for example:

- assert(variable, `${input.id.name} not defined`)
+ if (!variable) {
+   throw new TradReferenceError(`${input.id.name} not defined`, ...someRequiredData)
+ }

How to collect errors?

Maybe you need to add a try...catch statement to the root level parse() function call, for example:

try {
  this.parse(input)
} catch (err) {
  if (err instanceof TradError) {
    // Handling error
  }
}

What should be the format of the output error message?

Refer friendly-errors-webpack-plugin:

lint

babel

posted by lc-soft over 5 years ago

Hey @arshadkazmi42, are you working on this? If not, can I give this a shot? Thanks

posted by kenanchristian over 5 years ago

@kenanchristian I got busy with some other work was not able to look into it. Please go ahead with it.

posted by arshadkazmi42 over 5 years ago

@lc-soft has funded $5.00 to this issue.


posted by issuehunt-app[bot] over 5 years ago

@lc-soft has rewarded $20.00 to @lc-soft. See it on IssueHunt

  • :moneybag: Total deposit: $25.00
  • :tada: Repository reward(10%): $2.50
  • :wrench: Service fee(10%): $2.50
posted by issuehunt-app[bot] over 5 years ago

Fund this Issue

$25.00
Rewarded

Rewarded pull request

Recent activities

lc-soft was rewarded for lc-soft/trad# 4
over 5 years ago
lc-soft submitted an output to  lc-soft/ trad# 4
over 5 years ago