Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit fe0ff2f

Browse files
committed
Improve error reporting when missing L1 files
We recently faced an issue where L1 files weren't reachable, and the error message produced was very misleading. If the function is checking for one file existing, we should check them both. And give a more useful error message when we find nothing.
1 parent 48e629f commit fe0ff2f

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

tesp/workflow.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import shutil
1111
import traceback
1212
import json
13+
from typing import Optional
14+
1315
import yaml
1416

1517
import luigi
@@ -334,11 +336,15 @@ def output(self):
334336
return luigi.LocalTarget(str(out_fname))
335337

336338
def run(self):
337-
def search_for_external_level1_metadata():
339+
def search_for_external_level1_metadata() -> Optional[Path]:
338340
if self.yamls_dir is None or self.yamls_dir == "":
339341
return None
340342

341343
level1 = Path(self.level1)
344+
345+
# Level1 is in a three-level directory structure, and we mirror it in the yaml_dir
346+
# like this:
347+
# '{yaml_dir}/2021/2021-02/25S150E-30S155E/{yaml}'
342348
result = (
343349
Path(self.yamls_dir)
344350
/ level1.parent.parent.parent.name
@@ -347,13 +353,18 @@ def search_for_external_level1_metadata():
347353
/ (level1.stem + ".odc-metadata.yaml")
348354
)
349355

350-
if not result.is_file():
351-
result = (
352-
Path(self.yamls_dir)
353-
/ level1.parent.parent.parent.name
354-
/ level1.parent.parent.name
355-
/ level1.parent.name
356-
/ (level1.stem + "." + self.granule + ".odc-metadata.yaml")
356+
# If a singular yaml doesn't exist, there could be separate granule yamls
357+
if not result.exists():
358+
result = result.with_name(
359+
f"{level1.stem}.{self.granule}.odc-metadata.yaml"
360+
)
361+
362+
if not result.exists():
363+
raise ValueError(
364+
"Could not find matching metadata for L1 in the given yaml directory."
365+
f"Tried with and without granule in path: {result.as_posix()!r} "
366+
f"for dataset {self.level1!r}. "
367+
f"(if you intended to use a sibling yaml file, don't specify a yaml directory)"
357368
)
358369

359370
return result

0 commit comments

Comments
 (0)