Skip to content

Commit

Permalink
More robust exception handling
Browse files Browse the repository at this point in the history
Also throw a couple errors for null strings in AS
  • Loading branch information
piepie62 committed Nov 10, 2022
1 parent d080cb7 commit 63eeba4
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 79 deletions.
17 changes: 17 additions & 0 deletions AS3/src/com/cff/anebe/BytecodeEditor.as
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ package com.cff.anebe
*/
public function Assemble(strings:Object, includeDebugInstructions:Boolean, replaceSWF:ByteArray = null):ByteArray
{
if (strings == null)
{
throw new Error("Cannot assemble null strings");
}

if (replaceSWF != null)
{
decompressAndSetSWF(replaceSWF);
Expand Down Expand Up @@ -169,6 +174,10 @@ package com.cff.anebe
*/
public function AssembleAsync(strings:Object, includeDebugInstructions:Boolean, replaceSWF:ByteArray = null):void
{
if (strings == null)
{
throw new Error("Cannot assemble null strings");
}
if (replaceSWF != null)
{
decompressAndSetSWF(replaceSWF);
Expand Down Expand Up @@ -213,6 +222,10 @@ package com.cff.anebe
*/
public function PartialAssemble(strings:Object, includeDebugInstructions:Boolean, replaceSWF:ByteArray = null):void
{
if (strings == null)
{
throw new Error("Cannot assemble null strings");
}
if (replaceSWF != null)
{
decompressAndSetSWF(replaceSWF);
Expand Down Expand Up @@ -249,6 +262,10 @@ package com.cff.anebe
*/
public function PartialAssembleAsync(strings:Object, includeDebugInstructions:Boolean, replaceSWF:ByteArray = null):void
{
if (strings == null)
{
throw new Error("Cannot assemble null strings");
}
if (replaceSWF != null)
{
decompressAndSetSWF(replaceSWF);
Expand Down
37 changes: 22 additions & 15 deletions Native/BytecodeEditor/include/ANEFunctions.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,29 @@ FREObject Assemble(FREContext, void* funcData, uint32_t argc, FREObject argv[])
DO_OR_FAIL("Failed to get argv[1] size", FREGetArrayLength(argv[1], &vecSize));

std::unordered_map<std::string, std::string> strings;
for (uint32_t i = 0; i < vecSize; i++)
try
{
FREObject str;
DO_OR_FAIL("Failed to get argv[1][i]", FREGetArrayElementAt(argv[1], i, &str));
char* key;
uint32_t keyLen;
DO_OR_FAIL("Failed to get argv[1][i]'s string value",
FREGetObjectAsUTF8(str, &keyLen, (const uint8_t**)&key));
FREObject str2;
DO_OR_FAIL("Failed to get argv[0][argv[1][i]]",
FREGetObjectProperty(argv[0], (const uint8_t*)key, &str2, nullptr));
char* val;
uint32_t valLen;
DO_OR_FAIL("Failed to get argv[0][argv[1][i]]'s string value",
FREGetObjectAsUTF8(str2, &valLen, (const uint8_t**)&val));
strings.emplace(key, val);
for (uint32_t i = 0; i < vecSize; i++)
{
FREObject str;
DO_OR_FAIL("Failed to get argv[1][i]", FREGetArrayElementAt(argv[1], i, &str));
char* key;
uint32_t keyLen;
DO_OR_FAIL("Failed to get argv[1][i]'s string value",
FREGetObjectAsUTF8(str, &keyLen, (const uint8_t**)&key));
FREObject str2;
DO_OR_FAIL("Failed to get argv[0][argv[1][i]]",
FREGetObjectProperty(argv[0], (const uint8_t*)key, &str2, nullptr));
char* val;
uint32_t valLen;
DO_OR_FAIL("Failed to get argv[0][argv[1][i]]'s string value",
FREGetObjectAsUTF8(str2, &valLen, (const uint8_t**)&val));
strings.emplace(key, val);
}
}
catch (const std::exception& e)
{
FAIL(std::string("Exception occurred while converting strings: ") + e.what());
}

return (editor->*Assembler)(std::move(strings), includeDebugInstructions);
Expand Down
26 changes: 13 additions & 13 deletions Native/BytecodeEditor/source/ASClassFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace
}
catch (std::exception& e)
{
FAIL(std::string("Exception") + e.what());
FAIL(std::string("Exception: ") + e.what());
}
catch (...)
{
Expand Down Expand Up @@ -184,7 +184,7 @@ namespace
}
catch (std::exception& e)
{
FAIL(std::string("Exception") + e.what());
FAIL(std::string("Exception: ") + e.what());
}
catch (...)
{
Expand Down Expand Up @@ -268,7 +268,7 @@ namespace
}
catch (std::exception& e)
{
FAIL(std::string("Exception") + e.what());
FAIL(std::string("Exception: ") + e.what());
}
catch (...)
{
Expand Down Expand Up @@ -297,7 +297,7 @@ namespace
}
catch (std::exception& e)
{
FAIL(std::string("Exception") + e.what());
FAIL(std::string("Exception: ") + e.what());
}
catch (...)
{
Expand Down Expand Up @@ -326,7 +326,7 @@ namespace
}
catch (std::exception& e)
{
FAIL(std::string("Exception") + e.what());
FAIL(std::string("Exception: ") + e.what());
}
catch (...)
{
Expand Down Expand Up @@ -429,7 +429,7 @@ namespace ASClass
}
catch (std::exception& e)
{
FAIL(std::string("Exception") + e.what());
FAIL(std::string("Exception: ") + e.what());
}
catch (...)
{
Expand Down Expand Up @@ -468,7 +468,7 @@ namespace ASClass
}
catch (std::exception& e)
{
FAIL(std::string("Exception") + e.what());
FAIL(std::string("Exception: ") + e.what());
}
catch (...)
{
Expand Down Expand Up @@ -498,7 +498,7 @@ namespace ASClass
}
catch (std::exception& e)
{
FAIL(std::string("Exception") + e.what());
FAIL(std::string("Exception: ") + e.what());
}
catch (...)
{
Expand Down Expand Up @@ -526,7 +526,7 @@ namespace ASClass
}
catch (std::exception& e)
{
FAIL(std::string("Exception") + e.what());
FAIL(std::string("Exception: ") + e.what());
}
catch (...)
{
Expand Down Expand Up @@ -573,7 +573,7 @@ namespace ASClass
}
catch (std::exception& e)
{
FAIL(std::string("Exception") + e.what());
FAIL(std::string("Exception: ") + e.what());
}
catch (...)
{
Expand Down Expand Up @@ -612,7 +612,7 @@ namespace ASClass
}
catch (std::exception& e)
{
FAIL(std::string("Exception") + e.what());
FAIL(std::string("Exception: ") + e.what());
}
catch (...)
{
Expand Down Expand Up @@ -642,7 +642,7 @@ namespace ASClass
}
catch (std::exception& e)
{
FAIL(std::string("Exception") + e.what());
FAIL(std::string("Exception: ") + e.what());
}
catch (...)
{
Expand Down Expand Up @@ -670,7 +670,7 @@ namespace ASClass
}
catch (std::exception& e)
{
FAIL(std::string("Exception") + e.what());
FAIL(std::string("Exception: ") + e.what());
}
catch (...)
{
Expand Down
Loading

0 comments on commit 63eeba4

Please sign in to comment.