Commit 2128aefb authored by Virgile Prevosto's avatar Virgile Prevosto

[kernel] Refine error message when a Filepath parameter is given wrong argument

parent 9480f3bd
......@@ -452,6 +452,7 @@ struct
(X: sig
include Parameter_sig.Input_with_arg
val existence : Filepath.existence
val file_kind: string
end) =
struct
......@@ -473,8 +474,12 @@ struct
try
Filepath.Normalized.of_string ~existence:X.existence s
with
| Filepath.No_file -> P.L.abort "file not found: '%s'" s
| Filepath.File_exists -> P.L.abort "file already exists: '%s'" s
| Filepath.No_file ->
P.L.abort "%s%sfile not found: '%s'"
X.file_kind (if X.file_kind = "" then "" else " ") s
| Filepath.File_exists ->
P.L.abort "%s file already exists: '%s'"
X.file_kind (if X.file_kind = "" then "" else " ") s
in
set fp
......@@ -1211,6 +1216,7 @@ struct
(X: sig
include Parameter_sig.Input_with_arg
val existence: Fc_Filepath.existence
val file_kind: string
end) =
Make_list
(struct
......@@ -1222,9 +1228,11 @@ struct
try of_string ~existence:X.existence s
with
| Fc_Filepath.No_file ->
P.L.abort "file '%s' does not exist" s
P.L.abort "%s%sfile '%s' does not exist"
X.file_kind (if X.file_kind = "" then "" else " ") s
| Fc_Filepath.File_exists ->
P.L.abort "file '%s' already exists" s
P.L.abort "%s%sfile '%s' already exists"
X.file_kind (if X.file_kind = "" then "" else " ") s
end)
(struct
include X
......
......@@ -527,6 +527,9 @@ module type Builder = sig
module Filepath(X: sig
include Input_with_arg
val existence: Filepath.existence
val file_kind: string
(** used in error message if the file does not exist where it should
and vice-versa. *)
end): Filepath
exception Cannot_build of string
......@@ -567,6 +570,8 @@ module type Builder = sig
(X: sig
include Input_with_arg
val existence: Fc_Filepath.existence
val file_kind: string
(** see [Filepath] module. *)
end): Filepath_list
(** Parameter is a map where multibindings are **not** allowed. *)
......
......@@ -251,6 +251,7 @@ module Filepath_list
(X: sig
include Input_with_arg
val existence: Filepath.existence
val file_kind: string
end) =
P.Filepath_list
(struct
......@@ -732,6 +733,7 @@ module LoadState =
let option_name = "-load"
let arg_name = "filename"
let existence = Filepath.Must_exist
let file_kind = "Frama-C state"
let help = "load a previously-saved session from file <filename>"
end)
......@@ -1233,6 +1235,7 @@ module Files = struct
let module_name = "Files"
let arg_name = ""
let help = ""
let file_kind = "source"
let existence = Filepath.Must_exist
end)
let () = Cmdline.use_cmdline_files set
......
......@@ -45,7 +45,9 @@ exception File_exists
- non-existing directories in [realpath] may lead to ENOTDIR errors,
but [normalize] may accept them.
@modify Aluminium-20160501 optional base_name. *)
@modify Aluminium-20160501 optional base_name.
@modify Frama-C+dev optional existence
*)
val normalize: ?existence:existence -> ?base_name:string -> string -> string
(** [relativize base_name file_name] returns a relative path name of
......@@ -56,8 +58,8 @@ val normalize: ?existence:existence -> ?base_name:string -> string -> string
val relativize: ?base_name:string -> string -> string
(** returns true if the file is relative to [base]
(that is, it is prefixed by [base_name]), or to the current working directory
if no base is specified.
(that is, it is prefixed by [base_name]), or to the current
working directory if no base is specified.
@since Aluminium-20160501 *)
val is_relative: ?base_name:string -> string -> bool
......@@ -92,7 +94,9 @@ module Normalized: sig
type t = private string
(** [of_string s] converts [s] into a normalized path.
@raise Invalid_argument if [s] is the empty string. *)
@raise Invalid_argument if [s] is the empty string.
@modify Frama-C+dev add optional existence parameter
*)
val of_string: ?existence:existence -> ?base_name:string -> string -> t
(** [to_pretty_string p] returns [p] prettified,
......
......@@ -9,5 +9,5 @@
[kernel] relativize(.): .
[kernel] relativize(./tests/..): .
[kernel] relativize(/a/bc/d,base_name:/a/b/): /a/bc/d
[kernel] User Error: file not found: 'nonexistent_file.sav'
[kernel] User Error: Frama-C state file not found: 'nonexistent_file.sav'
[kernel] Frama-C aborted: invalid user input.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment