Skip to content

Commit

Permalink
Use functions that show line/column errors when parsing special fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonidas-from-XIV committed Mar 22, 2022
1 parent c02cacd commit 3aadbbd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 12 additions & 8 deletions lib/source_opam_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,20 @@ module Opam_provided = struct
let from_opam_value opam_chunk =
let open Result.O in
let* names =
match opam_chunk.OpamParserTypes.FullPos.pelem with
| OpamParserTypes.FullPos.String s -> Ok [ s ]
| List items ->
items.OpamParserTypes.FullPos.pelem
match (opam_chunk : OpamParserTypes.FullPos.value) with
| { pelem = String s; _ } -> Ok [ s ]
| { pelem = List items; _ } ->
items.pelem
|> List.map ~f:(fun item ->
match item.OpamParserTypes.FullPos.pelem with
| OpamParserTypes.FullPos.String s -> Ok s
| _ -> Error (`Msg "String required"))
match (item : OpamParserTypes.FullPos.value) with
| { pelem = String s; _ } -> Ok s
| otherwise ->
Opam.Pos.unexpected_value_error ~expected:"a string"
otherwise)
|> Result.List.all
| _ -> Error (`Msg "String or List required")
| otherwise ->
Opam.Pos.unexpected_value_error
~expected:"a string or a list of strings" otherwise
in
let names = List.map ~f:OpamPackage.Name.of_string names in
Ok (OpamPackage.Name.Set.of_list names)
Expand Down
4 changes: 2 additions & 2 deletions test/bin/opam-provided.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ be ignored is not a string.
42

$ opam-monorepo lock warning > /dev/null
opam-monorepo: String or List required
opam-monorepo: Error in opam file $TESTCASE_ROOT/warning.opam, [8:31]-[8:33]: Expected a string or a list of strings, got: 42
[1]

Similarly, we accept a list but it needs to be a list of strings which this is
Expand All @@ -121,5 +121,5 @@ not:
$ opam show --no-lint --raw -fx-opam-monorepo-opam-provided ./warning-list.opam
42 "fourtytwo"
$ opam-monorepo lock warning > /dev/null
opam-monorepo: String or List required
opam-monorepo: Error in opam file $TESTCASE_ROOT/warning.opam, [8:31]-[8:33]: Expected a string or a list of strings, got: 42
[1]

0 comments on commit 3aadbbd

Please sign in to comment.