-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Can't use standard library module within the standard library (?) #8839
Copy link
Copy link
Closed
Labels
A:std-libraryDefining and improving the standard library written in NuDefining and improving the standard library written in Nu
Milestone
Description
Describe the bug
Trying to add a call to std log info in crates/nu-std/lib/dirs.nu for, e.g, std dirs next, another module in the standard library.
It would be a grave restriction indeed if some commands in the standard library could not be used within other commands of the standard library.
How to reproduce
- in crates/nu-std/lib/dirs.nu (for example), add
use std log infoin either of the locations indicated below (or both). - `〉cargo run -- -c 'use std *; dirs next'
- or do a build and run the binary:
> cargo build; target/debug/nu -c 'use std *; dirs next'
Expected behavior
Info log output from invoked dirs next command
Screenshots
10 repetitions of the 'module not found' error, all from the same source line.
~/src/rust/nushell〉cargo run -- -c 'use std *; dirs next'
Finished dev [unoptimized + debuginfo] target(s) in 0.25s
Running `target/debug/nu -c 'use std *; dirs next'`
Error: nu::parser::module_not_found
× Module not found.
╭─[dirs:33:1]
33 │ ] {
34 │ use std "log info"
· ─┬─
· ╰── module not found
35 │
╰────
help: module files and their paths must be available before your script is run as parsing occurs before anything
is evaluated
Error: nu::parser::module_not_found
× Module not found.
╭─[dirs:33:1]
33 │ ] {
34 │ use std "log info"
· ─┬─
· ╰── module not found
35 │
╰────
help: module files and their paths must be available before your script is run as parsing occurs before anything
is evaluated
Error: nu::parser::module_not_found
× Module not found.
╭─[dirs:33:1]
33 │ ] {
34 │ use std "log info"
· ─┬─
· ╰── module not found
35 │
╰────
help: module files and their paths must be available before your script is run as parsing occurs before anything
is evaluated
Error: nu::parser::module_not_found
× Module not found.
╭─[dirs:33:1]
33 │ ] {
34 │ use std "log info"
· ─┬─
· ╰── module not found
35 │
╰────
help: module files and their paths must be available before your script is run as parsing occurs before anything
is evaluated
Error: nu::parser::module_not_found
× Module not found.
╭─[dirs:33:1]
33 │ ] {
34 │ use std "log info"
· ─┬─
· ╰── module not found
35 │
╰────
help: module files and their paths must be available before your script is run as parsing occurs before anything
is evaluated
Error: nu::parser::module_not_found
× Module not found.
╭─[dirs:33:1]
33 │ ] {
34 │ use std "log info"
· ─┬─
· ╰── module not found
35 │
╰────
help: module files and their paths must be available before your script is run as parsing occurs before anything
is evaluated
Error: nu::parser::module_not_found
× Module not found.
╭─[dirs:33:1]
33 │ ] {
34 │ use std "log info"
· ─┬─
· ╰── module not found
35 │
╰────
help: module files and their paths must be available before your script is run as parsing occurs before anything
is evaluated
Error: nu::parser::module_not_found
× Module not found.
╭─[dirs:33:1]
33 │ ] {
34 │ use std "log info"
· ─┬─
· ╰── module not found
35 │
╰────
help: module files and their paths must be available before your script is run as parsing occurs before anything
is evaluated
Error: nu::parser::module_not_found
× Module not found.
╭─[dirs:33:1]
33 │ ] {
34 │ use std "log info"
· ─┬─
· ╰── module not found
35 │
╰────
help: module files and their paths must be available before your script is run as parsing occurs before anything
is evaluated
Error: nu::parser::module_not_found
× Module not found.
╭─[dirs:33:1]
33 │ ] {
34 │ use std "log info"
· ─┬─
· ╰── module not found
35 │
╰────
help: module files and their paths must be available before your script is run as parsing occurs before anything
is evaluated
thread 'main' panicked at 'Internal error: can't run a predeclaration without a body', crates/nu-protocol/src/signature.rs:686:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: nu::shell::column_not_found
Configuration
| key | value |
|---|---|
| version | 0.78.1 |
| branch | stdlib_contributing |
| commit_hash | f2b977b |
| build_os | linux-x86_64 |
| build_target | x86_64-unknown-linux-gnu |
| rust_version | rustc 1.66.1 (90743e729 2023-01-10) |
| rust_channel | 1.66.1-x86_64-unknown-linux-gnu |
| cargo_version | cargo 1.66.1 (ad779e08b 2023-01-10) |
| build_time | 2023-04-07 21:17:57 -04:00 |
| build_rust_channel | debug |
| features | default, zip |
| installed_plugins |
Additional context
Here's the relevant chunk of dirs.nu:
# Maintain a list of working directories and navigates them
use std "log info"
# the directory stack
export-env {
let-env DIRS_POSITION = 0
let-env DIRS_LIST = [($env.PWD | path expand)]
}
# Add one or more directories to the list.
# PWD becomes first of the newly added directories.
export def-env "dirs add" [
...paths: string # directory or directories to add to working list
] {
mut abspaths = []
for p in $paths {
let exp = ($p | path expand)
if ($exp | path type) != 'dir' {
let span = (metadata $p).span
error make {msg: "not a directory", label: {text: "not a directory", start: $span.start, end: $span.end } }
}
$abspaths = ($abspaths | append $exp)
}
let-env DIRS_LIST = ($env.DIRS_LIST | insert ($env.DIRS_POSITION + 1) $abspaths | flatten)
let-env DIRS_POSITION = $env.DIRS_POSITION + 1
_fetch 0
}
# Advance to the next directory in the list or wrap to beginning.
export def-env "dirs next" [
N:int = 1 # number of positions to move.
] {
use std "log info"
_fetch $N
log info $"advancing to position ($env.DIRS_POSITION)"
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A:std-libraryDefining and improving the standard library written in NuDefining and improving the standard library written in Nu