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

[BUG] Error message is terminated for code errors but not message errors #510

Closed
hdwalters opened this issue Oct 10, 2024 · 2 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@hdwalters
Copy link
Contributor

hdwalters commented Oct 10, 2024

Describe the bug
When Amber shows a code based error message, for example caused by a syntax error, it terminates the last line:

hwalters@Ghostwheel ~/git/amber (master) 
$ amber glob.ab
 ERROR  Function 'glob' does not exist
at glob.ab:4:20

3| 
4| loop file in trust glob("*.txt") {
5|     echo "Found file {file}"
hwalters@Ghostwheel ~/git/amber (master) 

However, when it shows a text error message, for example caused by a missing source file, it does not:

hwalters@Ghostwheel ~/git/amber (master) 
$ amber missing.ab
 ERROR  No such file or directory (os error 2)hwalters@Ghostwheel ~/git/amber (master) 

To Reproduce
Run Amber from the command line, with arguments as above.

Expected behavior
Amber should terminate the last line in both cases.

Additional context
I tracked this down to Message::show() in the Heraclitus compiler:

pub fn show(&self) {
    // If this error is based in code
    if !self.trace.is_empty() {
        Logger::new(self.kind.clone(), &self.trace)
            .header(self.kind.clone())
            .line(self.message.clone()) // <=================== Logger::line() calls eprintln!()
            .path()
            .snippet(self.code.clone())
            .line(self.comment.clone());
    }
    // If this error is a message error
    else {
        Logger::new(self.kind.clone(), &self.trace)
            .header(self.kind.clone())
            .text(self.message.clone()) // <=================== Logger::text() calls eprint!()
            .padded_line(self.comment.clone());
    }
}
@hdwalters hdwalters added the bug Something isn't working label Oct 10, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New in Amber Project Oct 10, 2024
@hdwalters hdwalters self-assigned this Oct 10, 2024
@Ph0enixKM
Copy link
Member

Yep. It should be a line(...) instead of text(...). Good catch!

@hdwalters
Copy link
Contributor Author

Fixed by #552.

@github-project-automation github-project-automation bot moved this from 🆕 New to 🏁 Done in Amber Project Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants