nushell/nushell

nushell should never (or rarely) panic

開放

#4,471 建立於 2022年2月14日

 (4 則留言) (0 個反應) (0 位負責人)Rust (2,129 個分叉)batch import
help wantedpanicpolishusage:system-shell

倉庫指標

星標
 (39,478 顆星)
PR 合併指標
 (平均合併 4天 1小時) (30 天內合併 123 個 PR)

描述

Related problem

Quite often (especially in testing the engine-q changes), panics occur - forcefully exiting the shell and closing whatever tab it was in (if exec or default shell was used to start it).

This is a horrible user experience for bugs related to completion or highlighting or other non-critical shell related features that could have reasonable fallbacks. In general rust standards advise panics be the absolute last resort for unrecoverable errors - and I don't think highlighting or completion fall (and even some lexer issues related to aliases) fall under unrecoverable.

Describe the solution you'd like

I'm proposing the removal of all or most panics (priority being on completion or highlighting first). I currently count 74 uses of panic as of fbaafaa4.

While certain panics are obviously not recoverable, I believe any of the ones in the completion or highlighting should be able to just fail with no completion or highlighting being done.

I think many of the panics are around incorrect spans and lexer parsing, and I would rather the CLI show incorrect characters, highlighting, or other odd behavior rather than having the shell forcefully exit on me - leaving me no options to backspace or recover.

I'm open to ideas around making this experience better if the above isn't the correct approach, and additional ideas around logging or error reporting in these cases would be helpful so that errors aren't just swallowed (and thus unreported)

Describe alternatives you've considered

I'm wondering if it's possible to refactor some of the panic cases into Results instead, allowing the highest level caller to handle them more gracefully such as disabling highlighting, reverting to functionality for an unrecognized command/syntax shape, etc.

Additional context and details

No response

貢獻者指南