decompme / decomp.me

Collaborative decompilation and reverse engineering website
https://decomp.me
MIT License
348 stars 108 forks source link

Site shouldn't explode if a compiler isn't available #1201

Closed mkst closed 2 months ago

mkst commented 2 months ago

When developing locally, if you no longer have a platform/compiler available and try to view a list of scratches that includes that compiler, everything breaks.

It would be better if the site broke more gracefully - perhaps hiding scratches without a compiler?

mkst commented 2 months ago

This is a quick n' dirty hack that works.:

diff --git a/backend/coreapp/serializers.py b/backend/coreapp/serializers.py
index c122c768..10312c7e 100644
--- a/backend/coreapp/serializers.py
+++ b/backend/coreapp/serializers.py
@@ -227,7 +227,12 @@ class ScratchSerializer(serializers.ModelSerializer[Scratch]):
         - If the scratch's compiler has a LanguageFlagSet in its flags, attempt to match a language flag against that
         - Otherwise, fallback to the compiler's default language
         """
-        compiler = compilers.from_id(scratch.compiler)
+        try:
+            compiler = compilers.from_id(scratch.compiler)
+        except APIException:
+            # TODO: We don't care about the language when displaying a scratch list!
+            return "C"
+
         language_flag_set = next(
             iter([i for i in compiler.flags if isinstance(i, LanguageFlagSet)]),
             None,

.. however, the Scratch serializer cares about the language, but the scratch lists do use the language - we could/should make another TerseScratch (or use that) for the scratch lists.