Skip to content

Print the filename during errors#209

Merged
certik merged 3 commits intoprefix-dev:mainfrom
certik:error
Jan 29, 2025
Merged

Print the filename during errors#209
certik merged 3 commits intoprefix-dev:mainfrom
certik:error

Conversation

@certik
Copy link
Collaborator

@certik certik commented Jan 25, 2025

Fixes #208.

@certik
Copy link
Collaborator Author

certik commented Jan 25, 2025

This now says:

~$ conda spawn -n myst
Filename: "/Users/ondrej/miniforge3/envs/myst/etc/conda/activate.d/libxml2_activate.sh"
Syntax error:   × Failed to parse input
  ╰─▶ Failure to parse at Pos((3, 35))
   ╭────
 1 │ if test -n "${XML_CATALOG_FILES:-}"; then
   ·                                   ┬
   ·                                   ╰── expected QUOTED_ESCAPE_CHAR, QUOTED_CHAR, VARIABLE_EXPANSION, SUB_COMMAND, or EXIT_STATUS
   ╰────
  help: expected QUOTED_ESCAPE_CHAR, QUOTED_CHAR, VARIABLE_EXPANSION,
        SUB_COMMAND, or EXIT_STATUS

Which is very helpful to see the filename.

@certik
Copy link
Collaborator Author

certik commented Jan 25, 2025

Ok, now it prints the filename unless it runs interactively, then it doesn't:

~/repos/shell(error)$ source a.sh
Filename: "/Users/ondrej/repos/shell/a.sh"
Syntax error:   × Failed to parse input
  ╰─▶ Failure to parse at Pos((5, 11))
   ╭────
 1 │ if test xx␊
   ·           ┬
   ·           ╰── expected binary_bash_conditional_op or binary_posix_conditional_op
   ╰────
  help: expected binary_bash_conditional_op or binary_posix_conditional_op
~/repos/shell(error)$ shell a.sh
Filename: "a.sh"
Syntax error:   × Failed to parse input
  ╰─▶ Failure to parse at Pos((5, 11))
   ╭────
 1 │ if test xx␊
   ·           ┬
   ·           ╰── expected binary_bash_conditional_op or binary_posix_conditional_op
   ╰────
  help: expected binary_bash_conditional_op or binary_posix_conditional_op
~/repos/shell(error)$ if test -n "${XML_CATALOG_FILES:-}"; then
Syntax error:   × Failed to parse input
  ╰─▶ Failure to parse at Pos((1, 35))
   ╭────
 1 │ if test -n "${XML_CATALOG_FILES:-}"; then
   ·                                   ┬
   ·                                   ╰── expected QUOTED_ESCAPE_CHAR, QUOTED_CHAR, VARIABLE_EXPANSION, SUB_COMMAND, or EXIT_STATUS
   ╰────
  help: expected QUOTED_ESCAPE_CHAR, QUOTED_CHAR, VARIABLE_EXPANSION,
        SUB_COMMAND, or EXIT_STATUS

@wolfv this is ready.

Do not print it in interactive mode, but print it when running scripts.
@certik
Copy link
Collaborator Author

certik commented Jan 29, 2025

@wolfv should we merge this, and implement a better solution later using miette?

@certik
Copy link
Collaborator Author

certik commented Jan 29, 2025

It looks like to do this using miette, we need to define our own source file in our error struct like this:

struct MyBad {
    // The Source that we're gonna be printing snippets out of.
    // This can be a String if you don't have or care about file names.
    #[source_code]
    src: NamedSource<String>,
    // Snippets and highlights can be included in the diagnostic!
    #[label("This bit here")]
    bad_bit: SourceSpan,
}

Let's do that later. For now this unblocks us to print the filename, which is essential for debugging. I am going to merge this and we can further improve upon it.

@certik certik merged commit b9ad359 into prefix-dev:main Jan 29, 2025
6 checks passed
@certik certik deleted the error branch January 29, 2025 23:22
@certik
Copy link
Collaborator Author

certik commented Jan 29, 2025

Oops, the main failed after merging, since this PR was out of sync. Fixed in #217.

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.

Show a file on error message

1 participant

Comments