Skip to content

Commit 0f960e5

Browse files
Set Python error if imports fail
1 parent 15f1458 commit 0f960e5

33 files changed

Lines changed: 245 additions & 108 deletions

src/interface/error.i

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// python-exiv2 - Python interface to libexiv2
22
// http://github.com/jim-easterbrook/python-exiv2
3-
// Copyright (C) 2021-24 Jim Easterbrook jim@jim-easterbrook.me.uk
3+
// Copyright (C) 2021-25 Jim Easterbrook jim@jim-easterbrook.me.uk
44
//
55
// This program is free software: you can redistribute it and/or modify
66
// it under the terms of the GNU General Public License as published by
@@ -58,8 +58,10 @@ static void log_to_python(int level, const char* msg) {
5858
return NULL;
5959
logger = PyObject_CallMethod(module, "getLogger", "(s)", "exiv2");
6060
Py_DECREF(module);
61-
if (!logger)
61+
if (!logger) {
62+
PyErr_SetString(PyExc_RuntimeError, "logging.getLogger failed.");
6263
return NULL;
64+
}
6365
Exiv2::LogMsg::setHandler(&log_to_python);
6466
}
6567
%}

src/interface/shared/enum.i

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// python-exiv2 - Python interface to libexiv2
22
// http://github.com/jim-easterbrook/python-exiv2
3-
// Copyright (C) 2023-24 Jim Easterbrook jim@jim-easterbrook.me.uk
3+
// Copyright (C) 2023-25 Jim Easterbrook jim@jim-easterbrook.me.uk
44
//
55
// This program is free software: you can redistribute it and/or modify
66
// it under the terms of the GNU General Public License as published by
@@ -145,8 +145,10 @@ static PyObject* Py_IntEnum = NULL;
145145
return NULL;
146146
Py_IntEnum = PyObject_GetAttrString(module, "IntEnum");
147147
Py_DECREF(module);
148-
if (!Py_IntEnum)
148+
if (!Py_IntEnum) {
149+
PyErr_SetString(PyExc_RuntimeError, "Import error: enum.IntEnum.");
149150
return NULL;
151+
}
150152
}
151153
}
152154

src/interface/shared/exception.i

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// python-exiv2 - Python interface to libexiv2
22
// http://github.com/jim-easterbrook/python-exiv2
3-
// Copyright (C) 2024 Jim Easterbrook jim@jim-easterbrook.me.uk
3+
// Copyright (C) 2024-25 Jim Easterbrook jim@jim-easterbrook.me.uk
44
//
55
// This program is free software: you can redistribute it and/or modify
66
// it under the terms of the GNU General Public License as published by
@@ -30,8 +30,11 @@ static PyObject* PyExc_Exiv2Error = NULL;
3030
fragment="import_exiv2") {
3131
{
3232
PyExc_Exiv2Error = PyObject_GetAttrString(exiv2_module, "Exiv2Error");
33-
if (!PyExc_Exiv2Error)
33+
if (!PyExc_Exiv2Error) {
34+
PyErr_SetString(PyExc_RuntimeError,
35+
"Import error: exiv2.Exiv2Error not found.");
3436
return NULL;
37+
}
3538
}
3639
}
3740

src/swig-0_27_7/basicio_wrap.cxx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6790,8 +6790,11 @@ SWIG_init(void) {
67906790

67916791
{
67926792
PyExc_Exiv2Error = PyObject_GetAttrString(exiv2_module, "Exiv2Error");
6793-
if (!PyExc_Exiv2Error)
6794-
return NULL;
6793+
if (!PyExc_Exiv2Error) {
6794+
PyErr_SetString(PyExc_RuntimeError,
6795+
"Import error: exiv2.Exiv2Error not found.");
6796+
return NULL;
6797+
}
67956798
}
67966799

67976800

@@ -6804,8 +6807,10 @@ SWIG_init(void) {
68046807
return NULL;
68056808
Py_IntEnum = PyObject_GetAttrString(module, "IntEnum");
68066809
Py_DECREF(module);
6807-
if (!Py_IntEnum)
6808-
return NULL;
6810+
if (!Py_IntEnum) {
6811+
PyErr_SetString(PyExc_RuntimeError, "Import error: enum.IntEnum.");
6812+
return NULL;
6813+
}
68096814
}
68106815

68116816
SWIG_Python_SetConstant(d, d == md ? public_interface : NULL, "Position",_create_enum_Exiv2_BasicIo_Position(

src/swig-0_27_7/datasets_wrap.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7883,8 +7883,11 @@ SWIG_init(void) {
78837883

78847884
{
78857885
PyExc_Exiv2Error = PyObject_GetAttrString(exiv2_module, "Exiv2Error");
7886-
if (!PyExc_Exiv2Error)
7887-
return NULL;
7886+
if (!PyExc_Exiv2Error) {
7887+
PyErr_SetString(PyExc_RuntimeError,
7888+
"Import error: exiv2.Exiv2Error not found.");
7889+
return NULL;
7890+
}
78887891
}
78897892

78907893

src/swig-0_27_7/easyaccess_wrap.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6404,8 +6404,11 @@ SWIG_init(void) {
64046404

64056405
{
64066406
PyExc_Exiv2Error = PyObject_GetAttrString(exiv2_module, "Exiv2Error");
6407-
if (!PyExc_Exiv2Error)
6408-
return NULL;
6407+
if (!PyExc_Exiv2Error) {
6408+
PyErr_SetString(PyExc_RuntimeError,
6409+
"Import error: exiv2.Exiv2Error not found.");
6410+
return NULL;
6411+
}
64096412
}
64106413

64116414
#if PY_VERSION_HEX >= 0x03000000

src/swig-0_27_7/error_wrap.cxx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5386,8 +5386,10 @@ SWIG_init(void) {
53865386
return NULL;
53875387
logger = PyObject_CallMethod(module, "getLogger", "(s)", "exiv2");
53885388
Py_DECREF(module);
5389-
if (!logger)
5390-
return NULL;
5389+
if (!logger) {
5390+
PyErr_SetString(PyExc_RuntimeError, "logging.getLogger failed.");
5391+
return NULL;
5392+
}
53915393
Exiv2::LogMsg::setHandler(&log_to_python);
53925394
}
53935395

@@ -5398,8 +5400,10 @@ SWIG_init(void) {
53985400
return NULL;
53995401
Py_IntEnum = PyObject_GetAttrString(module, "IntEnum");
54005402
Py_DECREF(module);
5401-
if (!Py_IntEnum)
5402-
return NULL;
5403+
if (!Py_IntEnum) {
5404+
PyErr_SetString(PyExc_RuntimeError, "Import error: enum.IntEnum.");
5405+
return NULL;
5406+
}
54035407
}
54045408

54055409
SWIG_Python_SetConstant(d, d == md ? public_interface : NULL, "ErrorCode",_create_enum_Exiv2_ErrorCode(

src/swig-0_27_7/exif_wrap.cxx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13576,8 +13576,11 @@ SWIG_init(void) {
1357613576

1357713577
{
1357813578
PyExc_Exiv2Error = PyObject_GetAttrString(exiv2_module, "Exiv2Error");
13579-
if (!PyExc_Exiv2Error)
13580-
return NULL;
13579+
if (!PyExc_Exiv2Error) {
13580+
PyErr_SetString(PyExc_RuntimeError,
13581+
"Import error: exiv2.Exiv2Error not found.");
13582+
return NULL;
13583+
}
1358113584
}
1358213585

1358313586

@@ -13610,8 +13613,10 @@ SWIG_init(void) {
1361013613
return NULL;
1361113614
Py_IntEnum = PyObject_GetAttrString(module, "IntEnum");
1361213615
Py_DECREF(module);
13613-
if (!Py_IntEnum)
13614-
return NULL;
13616+
if (!Py_IntEnum) {
13617+
PyErr_SetString(PyExc_RuntimeError, "Import error: enum.IntEnum.");
13618+
return NULL;
13619+
}
1361513620
}
1361613621

1361713622
builtin_base_count = 0;

src/swig-0_27_7/image_wrap.cxx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9201,8 +9201,11 @@ SWIG_init(void) {
92019201

92029202
{
92039203
PyExc_Exiv2Error = PyObject_GetAttrString(exiv2_module, "Exiv2Error");
9204-
if (!PyExc_Exiv2Error)
9205-
return NULL;
9204+
if (!PyExc_Exiv2Error) {
9205+
PyErr_SetString(PyExc_RuntimeError,
9206+
"Import error: exiv2.Exiv2Error not found.");
9207+
return NULL;
9208+
}
92069209
}
92079210

92089211

@@ -9217,8 +9220,10 @@ SWIG_init(void) {
92179220
return NULL;
92189221
Py_IntEnum = PyObject_GetAttrString(module, "IntEnum");
92199222
Py_DECREF(module);
9220-
if (!Py_IntEnum)
9221-
return NULL;
9223+
if (!Py_IntEnum) {
9224+
PyErr_SetString(PyExc_RuntimeError, "Import error: enum.IntEnum.");
9225+
return NULL;
9226+
}
92229227
}
92239228

92249229
SWIG_Python_SetConstant(d, d == md ? public_interface : NULL, "ImageType",_create_enum_Exiv2_ImageType(

src/swig-0_27_7/iptc_wrap.cxx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11832,8 +11832,11 @@ SWIG_init(void) {
1183211832

1183311833
{
1183411834
PyExc_Exiv2Error = PyObject_GetAttrString(exiv2_module, "Exiv2Error");
11835-
if (!PyExc_Exiv2Error)
11836-
return NULL;
11835+
if (!PyExc_Exiv2Error) {
11836+
PyErr_SetString(PyExc_RuntimeError,
11837+
"Import error: exiv2.Exiv2Error not found.");
11838+
return NULL;
11839+
}
1183711840
}
1183811841

1183911842

@@ -11866,8 +11869,10 @@ SWIG_init(void) {
1186611869
return NULL;
1186711870
Py_IntEnum = PyObject_GetAttrString(module, "IntEnum");
1186811871
Py_DECREF(module);
11869-
if (!Py_IntEnum)
11870-
return NULL;
11872+
if (!Py_IntEnum) {
11873+
PyErr_SetString(PyExc_RuntimeError, "Import error: enum.IntEnum.");
11874+
return NULL;
11875+
}
1187111876
}
1187211877

1187311878
builtin_base_count = 0;

0 commit comments

Comments
 (0)