Skip to content

Commit

Permalink
style(logic): make error messages more clear
Browse files Browse the repository at this point in the history
Co-authored-by: Arnaud Mimart <[email protected]>
  • Loading branch information
bdeneux and amimart committed Jun 20, 2023
1 parent 5b60b4c commit 2fe711c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions x/logic/predicate/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func ReadString(vm *engine.VM, stream, length, result engine.Term, cont engine.C
var s *engine.Stream
switch st := env.Resolve(stream).(type) {
case engine.Variable:
return engine.Error(fmt.Errorf("read_string/3: stream could not be a variable"))
return engine.Error(fmt.Errorf("read_string/3: stream cannot be a variable"))
case *engine.Stream:
s = st
default:
Expand All @@ -69,12 +69,12 @@ func ReadString(vm *engine.VM, stream, length, result engine.Term, cont engine.C
if errors.Is(err, io.EOF) || totalLen >= maxLength {
break
}
return engine.Error(fmt.Errorf("read_string/3: error occurs reading stream: %w", err))
return engine.Error(fmt.Errorf("read_string/3: couldn't read stream: %w", err))
}
totalLen += uint64(l)
_, err = builder.WriteRune(r)
if err != nil {
return engine.Error(fmt.Errorf("read_string/3: failed write string: %w", err))
return engine.Error(fmt.Errorf("read_string/3: couldn't write string: %w", err))
}
}

Expand Down
2 changes: 1 addition & 1 deletion x/logic/predicate/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestReadString(t *testing.T) {
{
input: "Hello World!",
query: `read_string(Stream, Len, data).`,
wantError: fmt.Errorf("read_string/3: stream could not be a variable"),
wantError: fmt.Errorf("read_string/3: stream cannot be a variable"),
wantSuccess: false,
},
}
Expand Down

0 comments on commit 2fe711c

Please sign in to comment.