Amber icon indicating copy to clipboard operation
Amber copied to clipboard

[BUG] Incorrect error location.

Open social-anthrax opened this issue 1 year ago • 6 comments

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.

social-anthrax avatar Sep 18 '24 11:09 social-anthrax

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.

social-anthrax avatar Sep 18 '24 11:09 social-anthrax

in ./sync.ab:6:1

is that the line on which you have if includes(merge_output, "Already up to date")?

b1ek avatar Sep 22 '24 06:09 b1ek

Probably the error should says "Expected iterable for function includes at first parameter".

Mte90 avatar Sep 23 '24 08:09 Mte90

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.

lens0021 avatar Jun 22 '25 00:06 lens0021

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 avatar Nov 22 '25 15:11 Ph0enixKM

@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 avatar Nov 24 '25 13:11 lens0021

@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 happened
  • test.ab:1:1 - position of the import that imported the faulty function
  • test.ab:1:2 - where the faulty function was called

Ph0enixKM avatar Dec 04 '25 10:12 Ph0enixKM