Skip to content

Screen reader-friendly errors#10122

Merged
fdncred merged 10 commits intonushell:mainfrom
JoaquinTrinanes:feature/narratable-errors
Aug 27, 2023
Merged

Screen reader-friendly errors#10122
fdncred merged 10 commits intonushell:mainfrom
JoaquinTrinanes:feature/narratable-errors

Conversation

@JoaquinTrinanes
Copy link
Copy Markdown
Contributor

@JoaquinTrinanes JoaquinTrinanes commented Aug 26, 2023

Description

This PR adds a new config item, error_style. It will render errors in a screen reader friendly mode when set to "plain". This is done using miette's own NarratableReportHandler, which seamlessly replaces the default one when needed.

Before:

Error: nu::shell::external_command

  × External command failed
   ╭─[entry #2:1:1]
 1 │ doesnt exist
   · ───┬──
   ·    ╰── executable was not found
   ╰────
  help: No such file or directory (os error 2)

After:

Error: External command failed
    Diagnostic severity: error
Begin snippet for entry #4 starting at line 1, column 1

snippet line 1: doesnt exist
    label at line 1, columns 1 to 6: executable was not found
diagnostic help: No such file or directory (os error 2)
diagnostic code: nu::shell::external_command

Things to be determined

  • Review naming. errors.style is not that consistent with the rest of the code. Menus use a style record, but table rendering mode is set via mode. As it's a single config, we're using error_style for now.
  • Should this kind of setting be toggable with one single parameter? accessibility.no_decorations or similar, which would adjust the style of both errors and tables accordingly.

User-Facing Changes

No changes by default, errors will be rendered differently if error_style is set to simple.

Tests + Formatting

After Submitting

There's a PR updating the docs over here nushell/nushell.github.io#1026

Copy link
Copy Markdown
Member

@amtoine amtoine left a comment

Choose a reason for hiding this comment

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

thanks a lot @JoaquinTrinanes for implementing this, it's a great step in the right direction for accessibility 🙏

i propose we simply wait for some feedback from @edhowland to make sure it's easier to read for them, and then it looks like we can land this 💪

@amtoine amtoine added the A:accessibility An issue to make Nushell more accessible to anyone label Aug 26, 2023
}

errors: {
style: "fancy" # "fancy" or "narratable" for screen reader-friendly error messages
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unless we have more error configs, I would not nest and instead use error_style: "fancy".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just moved it outside to a single option in 281c1af.

I noticed that some config options are reconstructed after failing validation, while others (specially more simple fields like strings) aren't. I still do the reconstruction for this option according to the rules™️

// Config record (self) mutation rules:
// * When parsing a config Record, if a config key error occurs, remove the key.
// * When parsing a config Record, if a config value error occurs, replace the value
// with a reconstructed Nu value for the current (unaltered) configuration for that setting.
// For instance:
// $env.config.ls.use_ls_colors = 2 results in an error, so
// the current use_ls_colors config setting is converted to a Value::Boolean and inserted in the
// record in place of the 2.

Happy to change it if I misunderstood :)

@kubouch
Copy link
Copy Markdown
Contributor

kubouch commented Aug 26, 2023

Great, thanks! Looks good to me as well.

header_on_separator: false # show header text on separator/border line
}

error_style: "fancy"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. There should be comments showing the available options for error_style so people know what the options are.
  2. I'm fine with fancy as our default, but I don't really like the term narratable. Maybe one of these is better. I kind of lean toward "simple".
  • plain
  • without_borders
  • screen_reader
  • simple
  • bare

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The term "narratable" might seem strange (not a native speaker), but I like that it conveys the purpose of the setting: to be narratable by screen readers. We could have simple or similar instead, but then it should be noted in the comment that it's mean to be screen reader--friendly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  1. I just added the comment back. It was there before but I accidentally deleted it in the last commit 😅
  2. fancy refers to how miette itself calls this style, and narratable follows the same "logic" (they call the report handler NarratableReportHandler). Agree, it sounds weird 😬 I'll set it to simple for now if that's ok? I'm not sure about how these kind of decisions should be made

Copy link
Copy Markdown
Contributor

@fdncred fdncred Aug 26, 2023

Choose a reason for hiding this comment

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

I'd sign off on it if edhowland agrees it's good. Since he's blind and uses nushell, I'd like to get his input before finalizing the name. I'll ask him in Discord #general https://discord.com/channels/601130461678272522/601130461678272524/1144979237707722752.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For those not following Discord, this is what edhowland said, "I read the PR and the comments and suggestions. I like either simple or plain. Prefer plain over simple. Reason: No truly hard and fast reason, but the 'bat' command (a replacement for 'cat' written in Rust) also implemented the default behaviour of using box drawing characters for the output for border decorations. To suppress this they added the [-p, --plain] option. So, screen reader users already have at least that one firmly planted in their memories. But I am only 1 dude. Also: plain <=> fancy seems like their are natural antonyms of each other. Thoughts?"

So, since there is a precedent with bat, I move that we maintain that precedent and name the two options fancy and plain for key error_style.

Are there further thoughts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed in 94295b8! :)

fdncred
fdncred previously approved these changes Aug 26, 2023
Copy link
Copy Markdown
Contributor

@fdncred fdncred left a comment

Choose a reason for hiding this comment

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

I like it. It seems to work as expected. Except for the "plain" text. That doesn't seem right. "entry #6" is probably right, which you can see with view files, but seems like it should say something other than that because that won't be super helpful.

💡 When you do view files you get a list of file names, a span, and size. If you want to view the contents of one of these "file names" like "entry #6", you can use view span like this.

 view span 336112 336125
force_error 1

image

But now that I look at it, it doesn't say force_error anywhere. I wonder why?

@fdncred fdncred dismissed their stale review August 26, 2023 21:28

I think something must be wrong

@JoaquinTrinanes
Copy link
Copy Markdown
Contributor Author

@fdncred I'm confused 🥲

force_error appears on the second to last line:

snippet line 1: force_error 1

It looks like this when split in 2 lines:

Error: oh no!
    Diagnostic severity: error
Begin snippet for entry #15 starting at line 1, column 1

snippet line 1: (force_error
snippet line 2: 1)
    label at line 2, column 1: here's the error

I don't know what could be done about the entry #N thing, as that appears for both error reporters and it's a value explicitly set for the call as the filename:

&format!("entry #{entry_num}"),

That will show the name of the file that errors when evaluating a file. I did a quick experiment replacing the filename type with Option and passing none to the eval_source function, and it will default to source (Begin snippet for source starting at line...)

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Aug 27, 2023

ya, you're right. maybe it's ok. thanks for looking into it. it just seems not as helpful. maybe it's as good as we can get with miette?

@JoaquinTrinanes
Copy link
Copy Markdown
Contributor Author

JoaquinTrinanes commented Aug 27, 2023

maybe it's as good as we can get with miette?

Not necessarily, it would be a matter of removing the default source from here and passing None instead of Entry #N. Looking at the miette source not having a filename should render Begin snippet starting at....

However, I briefly tried and couldn't find an easy way to do it without the need to change the parser quite a bit. I'll be happy to further look into this but I think something of that scope should be another PR 😄

And there's always the option of creating our own report handler of course 😌

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Aug 27, 2023

ok, let's move forward with this. It's not perfect but provides a feature that's better than we had before for our screen reader community. Thanks!

@fdncred fdncred merged commit cc805f3 into nushell:main Aug 27, 2023
@fdncred fdncred added the notes:mention Include the release notes summary in the "Hall of Fame" section label Aug 27, 2023
@JoaquinTrinanes JoaquinTrinanes deleted the feature/narratable-errors branch August 27, 2023 12:03
horasal pushed a commit to horasal/nushell that referenced this pull request Aug 28, 2023
- Hopefully closes nushell#10120  

# Description

This PR adds a new config item, `error_style`. It will render errors in
a screen reader friendly mode when set to `"simple"`. This is done using
`miette`'s own `NarratableReportHandler`, which seamlessly replaces the
default one when needed.

Before:
```
Error: nu::shell::external_command

  × External command failed
   ╭─[entry nushell#2:1:1]
 1 │ doesnt exist
   · ───┬──
   ·    ╰── executable was not found
   ╰────
  help: No such file or directory (os error 2)
```

After:
```
Error: External command failed
    Diagnostic severity: error
Begin snippet for entry nushell#4 starting at line 1, column 1

snippet line 1: doesnt exist
    label at line 1, columns 1 to 6: executable was not found
diagnostic help: No such file or directory (os error 2)
diagnostic code: nu::shell::external_command

```

## Things to be determined

- ~Review naming. `errors.style` is not _that_ consistent with the rest
of the code. Menus use a `style` record, but table rendering mode is set
via `mode`.~ As it's a single config, we're using `error_style` for now.
- Should this kind of setting be toggable with one single parameter?
`accessibility.no_decorations` or similar, which would adjust the style
of both errors and tables accordingly.

# User-Facing Changes

No changes by default, errors will be rendered differently if
`error_style` is set to `simple`.

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting

There's a PR updating the docs over here
nushell/nushell.github.io#1026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:accessibility An issue to make Nushell more accessible to anyone notes:mention Include the release notes summary in the "Hall of Fame" section

Projects

None yet

4 participants