[erlang-questions] error handling in docbuilder

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Wed Mar 19 14:14:37 CET 2008


I came across the following code in docb_transform.erl (docbuilder):

file(File0, RawOpts) ->
     File = filename:rootname(File0), % without extension
     Ext = case filename:extension(File0) of
               ".xml" -> ".xml";
               ".sgml" -> ".sgml";
               "" ->
                   %% If the file is given without extension, we try to
                   %% infer if the source file is XML or SGML.
                   %% SGML is supported *internally within OTP* for
                   %% backwards compatibility reasons.
                   case filelib:is_regular(File++".xml") of
                       true -> ".xml";
                       false -> ".sgml"
                   end;
               _Ext0 -> % this is probably an error...
                   ".xml"
           end,

The catch-all clause that takes whatever unknown extension
given by the caller and changes it to ".xml" seems a bit
too "flexible" for my taste. If the caller provides an
unsupported extension, wouldn't it be better to return
an error?

Another gripe, while I'm at it, is that docb_util.erl
uses e.g. catch Mod:top(), if a {html_mod, Mod} option
has been specified, and silently ignores {'EXIT',undef}.

But if the 'undef' is due to the fact that Mod cannot
be found, this ought to be reported as an error.
While all functions in the callback module are optional,
clearly if a callback module has been specified, it must
be considered an error if the module itself cannot be
found.

BR,
Ulf W



More information about the erlang-questions mailing list