Skip to content

Commit f6e9c75

Browse files
authored
Merge pull request #51 from wave-hm/show_gsapi_error
Fix to read inner log on Ghostscript API error
2 parents af5315e + 0bc7ee4 commit f6e9c75

4 files changed

Lines changed: 52 additions & 6 deletions

File tree

Applications/Converter/Main/Sources/Message.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public static OpenFileMessage ForUserProgram(SettingFolder src)
221221
CryptographicException => Surface.Texts.Error_Digest,
222222
EncryptionException => Surface.Texts.Error_MergePassword,
223223
PostProcessException => Surface.Texts.Error_PostProcess,
224-
GsApiException e => string.Format(Surface.Texts.Error_Ghostscript, e.Status),
224+
GsApiException e => System.IO.File.ReadAllText(e.logPath),
225225
ArgumentException => src.Message,
226226
_ => $"{src.Message} ({src.GetType().Name})",
227227
};

Libraries/Generating/Sources/Converter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public void Invoke(IEnumerable<string> sources, string dest)
276276

277277
Logger.Debug(args.Join(" "));
278278
Io.CreateDirectory(Io.GetDirectoryName(dest));
279-
GsApi.Invoke(args, Temp);
279+
GsApi.Invoke(args, Temp, Log);
280280
}
281281

282282
/* --------------------------------------------------------------------- */

Libraries/Generating/Sources/Internal/GsApi.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static GsInformation Information
7373
/// </summary>
7474
///
7575
/* --------------------------------------------------------------------- */
76-
public static void Invoke(string[] raw, string tmp) => SetTemp(tmp, () =>
76+
public static void Invoke(string[] raw, string tmp, string log) => SetTemp(tmp, () =>
7777
{
7878
_ = NativeMethods.NewInstance(out var core, IntPtr.Zero);
7979
if (core == IntPtr.Zero) throw new GsApiException(GsApiStatus.UnknownError, "gsapi_new_instance");
@@ -84,7 +84,7 @@ public static void Invoke(string[] raw, string tmp) => SetTemp(tmp, () =>
8484
foreach (var e in raw) args.Add(ToUtf8(e));
8585
NativeMethods.SetArgEncoding(core, 1 /*GS_ARG_ENCODING_UTF8*/ );
8686
var code = NativeMethods.InitWithArgs(core, args.Count, args.ToArray());
87-
if (code < 0 && code != (int)GsApiStatus.Quit && code != (int)GsApiStatus.Info) throw new GsApiException(code);
87+
if (code < 0 && code != (int)GsApiStatus.Quit && code != (int)GsApiStatus.Info) throw new GsApiException(code, log);
8888
}
8989
finally
9090
{

Libraries/Generating/Sources/Internal/GsApiException.cs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ public GsApiException(int status) :
5555
///
5656
/// <summary>
5757
/// Initializes a new instance of the GsApiException class with
58+
/// the specified status and message, log.
59+
/// </summary>
60+
///
61+
/// <param name="status">Status code.</param>
62+
/// <param name="message">Message.</param>
63+
/// <param name="log"> Filepath of GS log.</param>
64+
///
65+
/* --------------------------------------------------------------------- */
66+
public GsApiException(int status, string log) :
67+
this((GsApiStatus)Enum.ToObject(typeof(GsApiStatus), status), $"{status} ({status:D})", log) { }
68+
/* --------------------------------------------------------------------- */
69+
///
70+
/// GsApiException
71+
///
72+
/// <summary>
73+
/// Initializes a new instance of the GsApiException class with
5874
/// the specified status.
5975
/// </summary>
6076
///
@@ -76,8 +92,28 @@ public GsApiException(GsApiStatus status) : this(status, $"{status} ({status:D})
7692
/// <param name="message">Message.</param>
7793
///
7894
/* --------------------------------------------------------------------- */
79-
public GsApiException(GsApiStatus status, string message) :
80-
base(message) => Status = status;
95+
public GsApiException(GsApiStatus status, string message) : this(status, message, null) { }
96+
97+
/* --------------------------------------------------------------------- */
98+
///
99+
/// GsApiException
100+
///
101+
/// <summary>
102+
/// Initializes a new instance of the GsApiException class with
103+
/// the specified status and message, log.
104+
/// </summary>
105+
///
106+
/// <param name="status">Status code.</param>
107+
/// <param name="message">Message.</param>
108+
/// <param name="log"> Filepath of GS log.</param>
109+
///
110+
/* --------------------------------------------------------------------- */
111+
public GsApiException(GsApiStatus status, string message, string log) :
112+
base(message)
113+
{
114+
Status = status;
115+
logPath = log;
116+
}
81117

82118
#endregion
83119

@@ -93,6 +129,16 @@ public GsApiException(GsApiStatus status, string message) :
93129
///
94130
/* --------------------------------------------------------------------- */
95131
public GsApiStatus Status { get; }
132+
/* --------------------------------------------------------------------- */
133+
///
134+
/// logPath
135+
///
136+
/// <summary>
137+
/// Gets the GS log filepath.
138+
/// </summary>
139+
///
140+
/* --------------------------------------------------------------------- */
141+
public string logPath { get; }
96142

97143
#endregion
98144
}

0 commit comments

Comments
 (0)