[BUG] Incorrect error location.
Describe the bug version: amber 0.3.5-alpha amber seems to throw an error when importing std/array.
To Reproduce
When running
import * from "std/text"
import { color_echo, exit, echo_info, error } from "std/env"
import * from "std/array"
amber throws
ERROR Expected iterable
at std/array:4:28
in ./sync.ab:6:1
Expected behavior Expected behaviour would be to import the array std lib.
Please disregard the previous error. It seems that there is instead a bug with the displayed location of where a bug occurs.
The broken code was later in the file and caused due to merge_output being a string and not an array.
let merge_output = $git merge upstream/master$ failed {
error("Failed to merge upstream into patched version", status)
}
if includes(merge_output, "Already up to date") {
echo_success("Patched version is already up to date with remote.")
exit(0)
} else {
echo_success("Succesfully upstream repo into patched version")
}
Expected behaviour
It would be expected that the error would show at the includes line instead of the import location.
in ./sync.ab:6:1
is that the line on which you have if includes(merge_output, "Already up to date")?
Probably the error should says "Expected iterable for function includes at first parameter".
To reproduce this in Amber 0.4.0,
import { array_contains } from "std/array"
array_contains("haystack", "needle")
The error is
ERROR Expected iterable at std/array:5:27 in -:1:1
Though the renaming functions reduced the possibility of this kind of mistake, anyway, the error is still incorrect.
This has already been fixed in upstream.
Code used to repro:
import { text_contains } from "std/text"
import { echo_success } from "std/env"
let merge_output = "Already up to date"
if text_contains(merge_output, "Already up to date") {
echo_success("Patched version is already up to date with remote.")
exit(0)
} else {
echo_success("Succesfully upstream repo into patched version")
}
Output
Patched version is already up to date with remote.
@Ph0enixKM I think you misunderstood the issue.
48d4ee81707c07ae2a0b56ebe18bee96597e1c88 still points out the incorrect error location.
import { array_contains } from "std/array"
array_contains("haystack", "needle")
Actual output:
ERROR Expected iterable
at std/array:5:27
in test.ab:1:1
Expected:
ERROR Expected iterable
at test.ab:2:16
@lens0021 thanks for clarifying this issue. We cannot replace the entire stack trace with just the line where the faulty function is called. I propose it to produce this stack trace instead:
ERROR Expected iterable
at std/array:5:27
in test.ab:1:1
in test.ab:2:16
Which is:
std/array:5:27- exact place where the error happenedtest.ab:1:1- position of the import that imported the faulty functiontest.ab:1:2- where the faulty function was called