Skip to content

Commit 63eeba4

Browse files
committed
More robust exception handling
Also throw a couple errors for null strings in AS
1 parent d080cb7 commit 63eeba4

4 files changed

Lines changed: 133 additions & 79 deletions

File tree

AS3/src/com/cff/anebe/BytecodeEditor.as

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ package com.cff.anebe
109109
*/
110110
public function Assemble(strings:Object, includeDebugInstructions:Boolean, replaceSWF:ByteArray = null):ByteArray
111111
{
112+
if (strings == null)
113+
{
114+
throw new Error("Cannot assemble null strings");
115+
}
116+
112117
if (replaceSWF != null)
113118
{
114119
decompressAndSetSWF(replaceSWF);
@@ -169,6 +174,10 @@ package com.cff.anebe
169174
*/
170175
public function AssembleAsync(strings:Object, includeDebugInstructions:Boolean, replaceSWF:ByteArray = null):void
171176
{
177+
if (strings == null)
178+
{
179+
throw new Error("Cannot assemble null strings");
180+
}
172181
if (replaceSWF != null)
173182
{
174183
decompressAndSetSWF(replaceSWF);
@@ -213,6 +222,10 @@ package com.cff.anebe
213222
*/
214223
public function PartialAssemble(strings:Object, includeDebugInstructions:Boolean, replaceSWF:ByteArray = null):void
215224
{
225+
if (strings == null)
226+
{
227+
throw new Error("Cannot assemble null strings");
228+
}
216229
if (replaceSWF != null)
217230
{
218231
decompressAndSetSWF(replaceSWF);
@@ -249,6 +262,10 @@ package com.cff.anebe
249262
*/
250263
public function PartialAssembleAsync(strings:Object, includeDebugInstructions:Boolean, replaceSWF:ByteArray = null):void
251264
{
265+
if (strings == null)
266+
{
267+
throw new Error("Cannot assemble null strings");
268+
}
252269
if (replaceSWF != null)
253270
{
254271
decompressAndSetSWF(replaceSWF);

Native/BytecodeEditor/include/ANEFunctions.tcc

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,29 @@ FREObject Assemble(FREContext, void* funcData, uint32_t argc, FREObject argv[])
4040
DO_OR_FAIL("Failed to get argv[1] size", FREGetArrayLength(argv[1], &vecSize));
4141

4242
std::unordered_map<std::string, std::string> strings;
43-
for (uint32_t i = 0; i < vecSize; i++)
43+
try
4444
{
45-
FREObject str;
46-
DO_OR_FAIL("Failed to get argv[1][i]", FREGetArrayElementAt(argv[1], i, &str));
47-
char* key;
48-
uint32_t keyLen;
49-
DO_OR_FAIL("Failed to get argv[1][i]'s string value",
50-
FREGetObjectAsUTF8(str, &keyLen, (const uint8_t**)&key));
51-
FREObject str2;
52-
DO_OR_FAIL("Failed to get argv[0][argv[1][i]]",
53-
FREGetObjectProperty(argv[0], (const uint8_t*)key, &str2, nullptr));
54-
char* val;
55-
uint32_t valLen;
56-
DO_OR_FAIL("Failed to get argv[0][argv[1][i]]'s string value",
57-
FREGetObjectAsUTF8(str2, &valLen, (const uint8_t**)&val));
58-
strings.emplace(key, val);
45+
for (uint32_t i = 0; i < vecSize; i++)
46+
{
47+
FREObject str;
48+
DO_OR_FAIL("Failed to get argv[1][i]", FREGetArrayElementAt(argv[1], i, &str));
49+
char* key;
50+
uint32_t keyLen;
51+
DO_OR_FAIL("Failed to get argv[1][i]'s string value",
52+
FREGetObjectAsUTF8(str, &keyLen, (const uint8_t**)&key));
53+
FREObject str2;
54+
DO_OR_FAIL("Failed to get argv[0][argv[1][i]]",
55+
FREGetObjectProperty(argv[0], (const uint8_t*)key, &str2, nullptr));
56+
char* val;
57+
uint32_t valLen;
58+
DO_OR_FAIL("Failed to get argv[0][argv[1][i]]'s string value",
59+
FREGetObjectAsUTF8(str2, &valLen, (const uint8_t**)&val));
60+
strings.emplace(key, val);
61+
}
62+
}
63+
catch (const std::exception& e)
64+
{
65+
FAIL(std::string("Exception occurred while converting strings: ") + e.what());
5966
}
6067

6168
return (editor->*Assembler)(std::move(strings), includeDebugInstructions);

Native/BytecodeEditor/source/ASClassFunctions.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace
7777
}
7878
catch (std::exception& e)
7979
{
80-
FAIL(std::string("Exception") + e.what());
80+
FAIL(std::string("Exception: ") + e.what());
8181
}
8282
catch (...)
8383
{
@@ -184,7 +184,7 @@ namespace
184184
}
185185
catch (std::exception& e)
186186
{
187-
FAIL(std::string("Exception") + e.what());
187+
FAIL(std::string("Exception: ") + e.what());
188188
}
189189
catch (...)
190190
{
@@ -268,7 +268,7 @@ namespace
268268
}
269269
catch (std::exception& e)
270270
{
271-
FAIL(std::string("Exception") + e.what());
271+
FAIL(std::string("Exception: ") + e.what());
272272
}
273273
catch (...)
274274
{
@@ -297,7 +297,7 @@ namespace
297297
}
298298
catch (std::exception& e)
299299
{
300-
FAIL(std::string("Exception") + e.what());
300+
FAIL(std::string("Exception: ") + e.what());
301301
}
302302
catch (...)
303303
{
@@ -326,7 +326,7 @@ namespace
326326
}
327327
catch (std::exception& e)
328328
{
329-
FAIL(std::string("Exception") + e.what());
329+
FAIL(std::string("Exception: ") + e.what());
330330
}
331331
catch (...)
332332
{
@@ -429,7 +429,7 @@ namespace ASClass
429429
}
430430
catch (std::exception& e)
431431
{
432-
FAIL(std::string("Exception") + e.what());
432+
FAIL(std::string("Exception: ") + e.what());
433433
}
434434
catch (...)
435435
{
@@ -468,7 +468,7 @@ namespace ASClass
468468
}
469469
catch (std::exception& e)
470470
{
471-
FAIL(std::string("Exception") + e.what());
471+
FAIL(std::string("Exception: ") + e.what());
472472
}
473473
catch (...)
474474
{
@@ -498,7 +498,7 @@ namespace ASClass
498498
}
499499
catch (std::exception& e)
500500
{
501-
FAIL(std::string("Exception") + e.what());
501+
FAIL(std::string("Exception: ") + e.what());
502502
}
503503
catch (...)
504504
{
@@ -526,7 +526,7 @@ namespace ASClass
526526
}
527527
catch (std::exception& e)
528528
{
529-
FAIL(std::string("Exception") + e.what());
529+
FAIL(std::string("Exception: ") + e.what());
530530
}
531531
catch (...)
532532
{
@@ -573,7 +573,7 @@ namespace ASClass
573573
}
574574
catch (std::exception& e)
575575
{
576-
FAIL(std::string("Exception") + e.what());
576+
FAIL(std::string("Exception: ") + e.what());
577577
}
578578
catch (...)
579579
{
@@ -612,7 +612,7 @@ namespace ASClass
612612
}
613613
catch (std::exception& e)
614614
{
615-
FAIL(std::string("Exception") + e.what());
615+
FAIL(std::string("Exception: ") + e.what());
616616
}
617617
catch (...)
618618
{
@@ -642,7 +642,7 @@ namespace ASClass
642642
}
643643
catch (std::exception& e)
644644
{
645-
FAIL(std::string("Exception") + e.what());
645+
FAIL(std::string("Exception: ") + e.what());
646646
}
647647
catch (...)
648648
{
@@ -670,7 +670,7 @@ namespace ASClass
670670
}
671671
catch (std::exception& e)
672672
{
673-
FAIL(std::string("Exception") + e.what());
673+
FAIL(std::string("Exception: ") + e.what());
674674
}
675675
catch (...)
676676
{

0 commit comments

Comments
 (0)