diff options
author | Dan Gudmundsson <dgud@erlang.org> | 2012-01-16 12:03:14 +0100 |
---|---|---|
committer | Dan Gudmundsson <dgud@erlang.org> | 2012-01-16 12:03:14 +0100 |
commit | 8e0a4ecff878eb2b632e5371597b85e2be45026a (patch) | |
tree | 08d4fc642faac9be6d765ba076fa673feb973ab1 /lib/observer/src/observer_lib.erl | |
parent | e9e96eaf8874e6fcd415228a363a98f71db3bc1b (diff) | |
download | otp-8e0a4ecff878eb2b632e5371597b85e2be45026a.tar.gz otp-8e0a4ecff878eb2b632e5371597b85e2be45026a.tar.bz2 otp-8e0a4ecff878eb2b632e5371597b85e2be45026a.zip |
[observer] Fix bugs in edit table object
Cancel button cause a crash, and editing an object without inserting
a dot at the end caused a crash.
Also improved error messages a bit.
Diffstat (limited to 'lib/observer/src/observer_lib.erl')
-rw-r--r-- | lib/observer/src/observer_lib.erl | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/lib/observer/src/observer_lib.erl b/lib/observer/src/observer_lib.erl index 967baa5c7a..5260861497 100644 --- a/lib/observer/src/observer_lib.erl +++ b/lib/observer/src/observer_lib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2011. All Rights Reserved. +%% Copyright Ericsson AB 2011-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -339,17 +339,37 @@ user_term(Parent, Title, Default) -> ?wxID_OK -> Str = wxTextEntryDialog:getValue(Dialog), wxTextEntryDialog:destroy(Dialog), - parse_string(Str); + parse_string(ensure_last_is_dot(Str)); ?wxID_CANCEL -> - wxTextEntryDialog:destroy(Dialog) + wxTextEntryDialog:destroy(Dialog), + cancel end. parse_string(Str) -> try - {ok, Tokens, _} = erl_scan:string(Str), - erl_parse:parse_term(Tokens) - catch _:{badmatch, {error, {_, _, Err}}} -> - {error, ["Parse error: ", Err]}; - _Err -> + Tokens = case erl_scan:string(Str) of + {ok, Ts, _} -> Ts; + {error, {_SLine, SMod, SError}, _} -> + throw(io_lib:format("~s", [SMod:format_error(SError)])) + end, + case erl_parse:parse_term(Tokens) of + {error, {_PLine, PMod, PError}} -> + throw(io_lib:format("~s", [PMod:format_error(PError)])); + Res -> Res + end + catch + throw:ErrStr -> + {error, ErrStr}; + _:_Err -> {error, ["Syntax error in: ", Str]} end. + +ensure_last_is_dot([]) -> + "."; +ensure_last_is_dot(String) -> + case lists:last(String) =:= $. of + true -> + String; + false -> + String ++ "." + end. |