File: error.cpp

package info (click to toggle)
exiv2 0.25-3.1+deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 23,696 kB
  • sloc: cpp: 73,318; sh: 10,328; ansic: 1,839; makefile: 700; python: 489; awk: 92; sed: 16; perl: 5
file content (212 lines) | stat: -rw-r--r-- 9,106 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// ***************************************************************** -*- C++ -*-
/*
 * Copyright (C) 2004-2015 Andreas Huggel <ahuggel@gmx.net>
 *
 * This program is part of the Exiv2 distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
 */
/*
  File:      error.cpp
  Version:   $Rev: 3777 $
  Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
  History:   02-Apr-05, ahu: created
 */
// *****************************************************************************
#include "rcsid_int.hpp"
EXIV2_RCSID("@(#) $Id: error.cpp 3777 2015-05-02 11:55:40Z ahuggel $")

// *****************************************************************************
// included header files
#include "error.hpp"
#include "i18n.h"                // NLS support.

// + standard includes
#include <iostream>
#include <string>
#include <cassert>

// *****************************************************************************
namespace {

    //! Helper structure defining an error message.
    struct ErrMsg {
        //! Comparison operator
        bool operator==(int code) const { return code_ == code; }

        int code_;                              //!< Error code
        const char* message_;                   //!< Error message
    };

    //! Complete list of Exiv2 exception error messages
    const ErrMsg errList[] = {
        { -1, N_("Error %0: arg2=%2, arg3=%3, arg1=%1.") },
        {  0, N_("Success") },
        {  1, "%1" }, // %1=error message
        {  2, "%1: Call to `%3' failed: %2" }, // %1=path, %2=strerror, %3=function that failed
        {  3, N_("This does not look like a %1 image") }, // %1=Image type
        {  4, N_("Invalid dataset name `%1'") }, // %1=dataset name
        {  5, N_("Invalid record name `%1'") }, // %1=record name
        {  6, N_("Invalid key `%1'") }, // %1=key
        {  7, N_("Invalid tag name or ifdId `%1', ifdId %2") }, // %1=tag name, %2=ifdId
        {  8, N_("Value not set") },
        {  9, N_("%1: Failed to open the data source: %2") }, // %1=path, %2=strerror
        { 10, N_("%1: Failed to open file (%2): %3") }, // %1=path, %2=mode, %3=strerror
        { 11, N_("%1: The file contains data of an unknown image type") }, // %1=path
        { 12, N_("The memory contains data of an unknown image type") },
        { 13, N_("Image type %1 is not supported") }, // %1=image type
        { 14, N_("Failed to read image data") },
        { 15, N_("This does not look like a JPEG image") },
        { 16, N_("%1: Failed to map file for reading and writing: %2") }, // %1=path, %2=strerror
        { 17, N_("%1: Failed to rename file to %2: %3") }, // %1=old path, %2=new path, %3=strerror
        { 18, N_("%1: Transfer failed: %2") }, // %1=path, %2=strerror
        { 19, N_("Memory transfer failed: %1") }, // %1=strerror
        { 20, N_("Failed to read input data") },
        { 21, N_("Failed to write image") },
        { 22, N_("Input data does not contain a valid image") },
        { 23, N_("Invalid ifdId %1") }, // %1=ifdId
        { 24, N_("Entry::setValue: Value too large (tag=%1, size=%2, requested=%3)") }, // %1=tag, %2=dataSize, %3=required size
        { 25, N_("Entry::setDataArea: Value too large (tag=%1, size=%2, requested=%3)") }, // %1=tag, %2=dataAreaSize, %3=required size
        { 26, N_("Offset out of range") },
        { 27, N_("Unsupported data area offset type") },
        { 28, N_("Invalid charset: `%1'") }, // %1=charset name
        { 29, N_("Unsupported date format") },
        { 30, N_("Unsupported time format") },
        { 31, N_("Writing to %1 images is not supported") }, // %1=image format
        { 32, N_("Setting %1 in %2 images is not supported") }, // %1=metadata type, %2=image format
        { 33, N_("This does not look like a CRW image") },
        { 34, N_("%1: Not supported") }, // %1=function
        { 35, N_("No namespace info available for XMP prefix `%1'") }, // %1=prefix
        { 36, N_("No prefix registered for namespace `%2', needed for property path `%1'") }, // %1=namespace
        { 37, N_("Size of %1 JPEG segment is larger than 65535 bytes") }, // %1=type of metadata (Exif, IPTC, JPEG comment)
        { 38, N_("Unhandled Xmpdatum %1 of type %2") }, // %1=key, %2=value type
        { 39, N_("Unhandled XMP node %1 with opt=%2") }, // %1=key, %2=XMP Toolkit option flags
        { 40, N_("XMP Toolkit error %1: %2") }, // %1=XMP_Error::GetID(), %2=XMP_Error::GetErrMsg()
        { 41, N_("Failed to decode Lang Alt property %1 with opt=%2") }, // %1=property path, %3=XMP Toolkit option flags
        { 42, N_("Failed to decode Lang Alt qualifier %1 with opt=%2") }, // %1=qualifier path, %3=XMP Toolkit option flags
        { 43, N_("Failed to encode Lang Alt property %1") }, // %1=key
        { 44, N_("Failed to determine property name from path %1, namespace %2") }, // %1=property path, %2=namespace
        { 45, N_("Schema namespace %1 is not registered with the XMP Toolkit") }, // %1=namespace
        { 46, N_("No namespace registered for prefix `%1'") }, // %1=prefix
        { 47, N_("Aliases are not supported. Please send this XMP packet to ahuggel@gmx.net `%1', `%2', `%3'") }, // %1=namespace, %2=property path, %3=value
        { 48, N_("Invalid XmpText type `%1'") }, // %1=type
        { 49, N_("TIFF directory %1 has too many entries") }, // %1=TIFF directory name
        { 50, N_("Multiple TIFF array element tags %1 in one directory") }, // %1=tag number
        { 51, N_("TIFF array element tag %1 has wrong type") }, // %1=tag number
        { 52, N_("%1 has invalid XMP value type `%2'") }, // %1=key, %2=value type
        { 58, N_("corrupted image metadata") }
    };

}

// *****************************************************************************
// class member definitions
namespace Exiv2 {

    LogMsg::Level LogMsg::level_ = LogMsg::warn; // Default output level
    LogMsg::Handler LogMsg::handler_ = LogMsg::defaultHandler;

    void LogMsg::defaultHandler(int level, const char* s)
    {
        switch (static_cast<LogMsg::Level>(level)) {
        case LogMsg::debug: std::cerr << "Debug: "; break;
        case LogMsg::info:  std::cerr << "Info: "; break;
        case LogMsg::warn:  std::cerr << "Warning: "; break;
        case LogMsg::error: std::cerr << "Error: "; break;
        case LogMsg::mute:  assert(false);
        }
        std::cerr << s;
    }

    AnyError::~AnyError() throw()
    {
    }

    //! @cond IGNORE
    template<>
    void BasicError<char>::setMsg()
    {
        std::string msg = _(errMsg(code_));
        std::string::size_type pos;
        pos = msg.find("%0");
        if (pos != std::string::npos) {
            msg.replace(pos, 2, toString(code_));
        }
        if (count_ > 0) {
            pos = msg.find("%1");
            if (pos != std::string::npos) {
                msg.replace(pos, 2, arg1_);
            }
        }
        if (count_ > 1) {
            pos = msg.find("%2");
            if (pos != std::string::npos) {
                msg.replace(pos, 2, arg2_);
            }
        }
        if (count_ > 2) {
            pos = msg.find("%3");
            if (pos != std::string::npos) {
                msg.replace(pos, 2, arg3_);
            }
        }
        msg_ = msg;
#ifdef EXV_UNICODE_PATH
        wmsg_ = s2ws(msg);
#endif
    }
    //! @endcond

#ifdef EXV_UNICODE_PATH
    template<>
    void BasicError<wchar_t>::setMsg()
    {
        std::string s = _(errMsg(code_));
        std::wstring wmsg(s.begin(), s.end());
        std::wstring::size_type pos;
        pos = wmsg.find(L"%0");
        if (pos != std::wstring::npos) {
            wmsg.replace(pos, 2, toBasicString<wchar_t>(code_));
        }
        if (count_ > 0) {
            pos = wmsg.find(L"%1");
            if (pos != std::wstring::npos) {
                wmsg.replace(pos, 2, arg1_);
            }
        }
        if (count_ > 1) {
            pos = wmsg.find(L"%2");
            if (pos != std::wstring::npos) {
                wmsg.replace(pos, 2, arg2_);
            }
        }
        if (count_ > 2) {
            pos = wmsg.find(L"%3");
            if (pos != std::wstring::npos) {
                wmsg.replace(pos, 2, arg3_);
            }
        }
        wmsg_ = wmsg;
        msg_ = ws2s(wmsg);
    }
#endif

    const char* errMsg(int code)
    {
        const ErrMsg* em = find(errList, code);
        return em ? em->message_ : "";
    }

}                                       // namespace Exiv2