Fix compiler deprecation warnings for Crystal 1.20+#1379
Conversation
Issue: None
# Why is this change necessary?
* Modern Crystal versions generate several deprecation warnings for outdated methods (Process::Status#exit_status, Time.monotonic, splat macro syntax, ::sleep).
# How does it address the issue
* Updated `exit_status` to `exit_code` in `src/amber/cli/commands/exec.cr`.
* Replaced `Time.monotonic` with `Time.instant` in `src/amber/cli/helpers/process_runner.cr`.
* Replaced `sleep 1` with `sleep 1.second` in `src/amber/cli/helpers/process_runner.cr`.
* Replaced double-brace macro splat syntax `{{*args}}` with `{{args.splat}}` in `src/amber/dsl/router.cr`.
# What side effects does this change have?
* None. Fixes compilation deprecation warnings when building the amber CLI binary.
Co-developed-by: Gemini AI <renich+gemini@woralelandia.com>
Signed-off-by: Rénich Bon Ćirić <renich@woralelandia.com>
…22) * Harden editor invocation against shell injection; fix Crystal 1.20 deprecations exec.cr and encrypt.cr previously called system("#{editor} #{filename}"), allowing shell metacharacters in the EDITOR env var or filename to execute arbitrary commands. Replace with Process.parse_arguments + Process.run so the editor string is word-split (supporting "code -w", "vim -u none", etc.) and the filename is passed as a literal argument with no shell involvement. Add regression specs asserting shell metacharacters in editor/filename do not execute. Fix pattern contributed by @tcoatswo in amberframework/amber#1376. process_runner.cr used Time.monotonic which is deprecated in Crystal 1.20.0 in favour of Time.instant (Time::Instant, introduced in 1.20.0). Replace both call sites. The shard.yml crystal floor is raised to >= 1.20.0 to match (see version bump commit). Fix contributed by @renich in amberframework/amber#1379. amber.js Channel.join/leave/push previously called this.socket.ws.send() without error handling; a dead WebSocket throws an uncaught DOMException in the browser. Wrap each send in try/catch with a fallback to _reconnect(). Fix pattern contributed by @jonsilverman50-star in amberframework/amber#1375. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Bump version to 2.0.1; raise Crystal floor to >= 1.20.0 Time.instant (used in process_runner.cr) was introduced in Crystal 1.20.0. Raise the shard.yml crystal constraint from >= 1.10.0 to >= 1.20.0 to reflect this requirement. Bump shard version 2.0.0 -> 2.0.1 to signal the patch release containing the exec/encrypt hardening and deprecation fixes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
|
Thanks for tracking down these deprecation warnings. Cleaning up Merging this into v1. For context on where these land in V2: the CLI was removed from the framework core entirely (exec.cr and process_runner.cr now live in the standalone amber_cli), and the router macro was rewritten with explicit named parameters, so the splat fix is superseded by design there. Your V2 is now public if you want to see where things are heading: #1383. We'd welcome the help. |
Description of the Change
When compiling the Amber framework under modern Crystal versions (e.g. 1.20+), several deprecation warnings are emitted. This Pull Request updates the deprecated methods to their modern equivalents:
Process::Status#exit_statustoProcess::Status#exit_codeinsrc/amber/cli/commands/exec.cr.Time.monotonicwithTime.instantinsrc/amber/cli/helpers/process_runner.cr.sleep 1with the modernsleep 1.secondspan-based signature insrc/amber/cli/helpers/process_runner.cr.{{*args}}with{{args.splat}}insrc/amber/dsl/router.cr.Alternate Designs
None. These changes follow standard deprecation warnings emitted during compilation.
Benefits
amberCLI binary under modern Crystal versions with 0 deprecation warnings.Possible Drawbacks
None.
Note: This PR was co-developed with the assistance of Gemini AI. The user (Rénich Bon Ćirić) has directed, reviewed, tested, and takes full responsibility for the code.