From 89fdc45b4540bc9d14854f2fdc7034bc0af5e2ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 20 Jun 2022 17:14:06 +0200 Subject: [PATCH] Manager: ignore small JS files Empty (or almost-empty) JS files are ignored by the job compiler. --- .../manager/job_compilers/scripts-for-unittest/empty.js | 0 internal/manager/job_compilers/scripts.go | 8 ++++++++ internal/manager/job_compilers/scripts_test.go | 1 + 3 files changed, 9 insertions(+) create mode 100644 internal/manager/job_compilers/scripts-for-unittest/empty.js 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)) }