diff --git a/internal/manager/job_compilers/scripts-for-unittest/empty.js b/internal/manager/job_compilers/scripts-for-unittest/empty.js new file mode 100644 index 00000000..e69de29b diff --git a/internal/manager/job_compilers/scripts.go b/internal/manager/job_compilers/scripts.go index c7e3c633..12d412b5 100644 --- a/internal/manager/job_compilers/scripts.go +++ b/internal/manager/job_compilers/scripts.go @@ -49,6 +49,14 @@ func (s *Service) loadScriptsFrom(filesystem fs.FS) error { continue } + if len(script_bytes) < 8 { + log.Debug(). + Str("script", filename). + Int("fileSizeBytes", len(script_bytes)). + Msg("ignoring tiny JS file, it is unlikely to be a job compiler script") + continue + } + program, err := goja.Compile(filename, string(script_bytes), true) if err != nil { log.Error().Err(err).Str("filename", filename).Msg("failed to compile script") diff --git a/internal/manager/job_compilers/scripts_test.go b/internal/manager/job_compilers/scripts_test.go index 7305c963..7a614d72 100644 --- a/internal/manager/job_compilers/scripts_test.go +++ b/internal/manager/job_compilers/scripts_test.go @@ -25,6 +25,7 @@ func TestLoadScriptsFrom_on_disk_js(t *testing.T) { expectKeys := map[string]bool{ "echo-and-sleep": true, "simple-blender-render": true, + // Should NOT contain an entry for 'empty.js'. } assert.Equal(t, expectKeys, keys(s.compilers)) }