Skip to content

Commit 47d1005

Browse files
authored
fix: better error message for missing artifacts (#973)
<!-- Pull requests are squashed and merged using: - their title as the commit message - their description as the commit body Having a good title and description is important for the users to get readable changelog. --> <!-- 1. Explain WHAT the change is about --> - Solve [MET-821](https://linear.app/metatypedev/issue/MET-821/bad-error-message-on-missing-deno-rt-deps) - Better error message for missing artifacts - Shared logic for artifact registration on postprocess <!-- 2. Explain WHY the change cannot be made simpler --> - <!-- 3. Explain HOW users should update their code --> #### Migration notes --- - [ ] The change comes with new or modified tests - [ ] Hard-to-understand functions have explanatory comments - [ ] End-user documentation is updated to reflect the change <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Consolidated the artifact registration process to support bulk handling of primary and dependency artifacts. - **Refactor** - Streamlined registration workflows across multiple runtime integrations, enhancing efficiency and clarity. - **Tests** - Added comprehensive tests to ensure robust error reporting when dependencies are missing. - Introduced a new test case to validate behavior for non-existent engine scripts. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 82600b5 commit 47d1005

File tree

10 files changed

+1029
-837
lines changed

10 files changed

+1029
-837
lines changed

deno.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/typegraph/core/src/utils/artifacts.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,44 @@ use common::typegraph::{runtimes::Artifact, Typegraph};
99

1010
pub trait ArtifactsExt {
1111
/// update the artifact meta, and register the artifact in the typegraph
12-
fn register_artifact(&self, artifact_path: PathBuf, tg: &mut Typegraph) -> Result<()>;
12+
fn register_artifacts(
13+
&self,
14+
tg: &mut Typegraph,
15+
entry: PathBuf,
16+
deps: Vec<PathBuf>,
17+
) -> Result<Vec<PathBuf>>;
1318
}
1419

1520
impl ArtifactsExt for FsContext {
16-
fn register_artifact(&self, path: PathBuf, tg: &mut Typegraph) -> Result<()> {
21+
fn register_artifacts(
22+
&self,
23+
tg: &mut Typegraph,
24+
entry: PathBuf,
25+
deps: Vec<PathBuf>,
26+
) -> Result<Vec<PathBuf>> {
27+
let mut registered_deps = vec![];
28+
self.register_artifact(tg, entry)?;
29+
for dep in deps {
30+
let artifacts = self.list_files(&[dep.to_string_lossy().to_string()]);
31+
if artifacts.is_empty() {
32+
return Err(format!(
33+
"no artifacts found for dependency '{}'",
34+
dep.to_string_lossy()
35+
)
36+
.into());
37+
}
38+
for artifact in artifacts.into_iter() {
39+
self.register_artifact(tg, artifact.clone())?;
40+
registered_deps.push(artifact);
41+
}
42+
}
43+
44+
Ok(registered_deps)
45+
}
46+
}
47+
48+
impl FsContext {
49+
fn register_artifact(&self, tg: &mut Typegraph, path: PathBuf) -> Result<()> {
1750
use std::collections::btree_map::Entry;
1851
if let Entry::Vacant(entry) = tg.meta.artifacts.entry(path) {
1952
let path = entry.key().to_path_buf();

src/typegraph/core/src/utils/postprocess/deno_rt.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,9 @@ impl PostProcessor for DenoProcessor {
2828
let mut mat_data: ModuleMatData =
2929
object_from_map(mat_data).map_err(|e| e.to_string())?;
3030

31-
fs_ctx.register_artifact(mat_data.entry_point.clone(), tg)?;
32-
31+
let entry_point = mat_data.entry_point.clone();
3332
let deps = std::mem::take(&mut mat_data.deps);
34-
for artifact in deps.into_iter() {
35-
let artifacts = fs_ctx.list_files(&[artifact.to_string_lossy().to_string()]);
36-
for artifact in artifacts.iter() {
37-
fs_ctx.register_artifact(artifact.clone(), tg)?;
38-
}
39-
mat_data.deps.extend(artifacts);
40-
}
41-
33+
mat_data.deps = fs_ctx.register_artifacts(tg, entry_point, deps)?;
4234
mat.data = map_from_object(mat_data).map_err(|e| e.to_string())?;
4335
}
4436
}

src/typegraph/core/src/utils/postprocess/python_rt.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,9 @@ impl PostProcessor for PythonProcessor {
3030
let mut mat_data: ModuleMatData =
3131
object_from_map(mat_data).map_err(|e| e.to_string())?;
3232

33-
fs_ctx.register_artifact(mat_data.entry_point.clone(), tg)?;
34-
33+
let entrypoint = mat_data.entry_point.clone();
3534
let deps = std::mem::take(&mut mat_data.deps);
36-
for artifact in deps.into_iter() {
37-
let artifacts = fs_ctx.list_files(&[artifact.to_string_lossy().to_string()]);
38-
for artifact in artifacts.iter() {
39-
fs_ctx.register_artifact(artifact.clone(), tg)?;
40-
}
41-
mat_data.deps.extend(artifacts);
42-
}
43-
35+
mat_data.deps = fs_ctx.register_artifacts(tg, entrypoint, deps)?;
4436
mat.data = map_from_object(mat_data).map_err(|e| e.to_string())?;
4537
}
4638
}

src/typegraph/core/src/utils/postprocess/substantial_rt.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,17 @@ impl SubstantialProcessor {
2121
impl PostProcessor for SubstantialProcessor {
2222
fn postprocess(self, tg: &mut Typegraph) -> Result<(), crate::errors::TgError> {
2323
let fs_ctx = FsContext::new(self.typegraph_dir.clone());
24-
let runtimes = std::mem::take(&mut tg.runtimes);
24+
let mut runtimes = std::mem::take(&mut tg.runtimes);
2525

26-
for runtime in runtimes.iter() {
26+
for runtime in runtimes.iter_mut() {
2727
if let TGRuntime::Known(known_runtime) = runtime {
2828
match known_runtime {
2929
runtimes::KnownRuntime::Substantial(data) => {
30-
for wf_description in &data.workflows {
31-
fs_ctx.register_artifact(wf_description.file.clone(), tg)?;
32-
33-
for artifact in &wf_description.deps {
34-
let artifacts: Vec<PathBuf> =
35-
fs_ctx.list_files(&[artifact.to_string_lossy().to_string()]);
36-
for artifact in artifacts.iter() {
37-
fs_ctx.register_artifact(artifact.clone(), tg)?;
38-
}
39-
}
30+
for wf_description in &mut data.workflows {
31+
let entrypoint = wf_description.file.clone();
32+
let deps = std::mem::take(&mut wf_description.deps);
33+
wf_description.deps =
34+
fs_ctx.register_artifacts(tg, entrypoint, deps)?;
4035
}
4136
}
4237
_ => continue,

src/typegraph/core/src/utils/postprocess/wasm_rt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl PostProcessor for WasmProcessor {
3434
}
3535
};
3636

37-
fs_ctx.register_artifact(data.wasm_artifact.clone(), tg)?;
37+
fs_ctx.register_artifacts(tg, data.wasm_artifact.clone(), vec![])?;
3838
}
3939

4040
tg.runtimes = runtimes;

tests/artifacts/artifacts_test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
import { Meta } from "test-utils/mod.ts";
55
import { join } from "@std/path/join";
66
import { exists } from "@std/fs/exists";
7-
import { assert, assertFalse } from "@std/assert";
7+
import {
8+
assert,
9+
assertFalse,
10+
assertRejects,
11+
assertStringIncludes,
12+
} from "@std/assert";
813
import { connect } from "redis";
914
import { S3Client } from "aws-sdk/client-s3";
1015
import { createBucket, hasObject, tryDeleteBucket } from "test-utils/s3.ts";
@@ -199,3 +204,19 @@ for (const { mode, ...options } of variants) {
199204
},
200205
);
201206
}
207+
208+
Meta.test(`Missing artifact`, async (t) => {
209+
await t.should("fail on missing artifact", async () => {
210+
await assertRejects(
211+
async () => {
212+
await t.engine("runtimes/deno/inexisting_dep.py");
213+
},
214+
);
215+
try {
216+
await t.engine("runtimes/deno/inexisting_dep.py");
217+
assert(false, "should have thrown");
218+
} catch (e) {
219+
assertStringIncludes(e.message, "no artifacts found for dependency");
220+
}
221+
});
222+
});

tests/e2e/nextjs/apollo/package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12-
"@apollo/client": "^3",
13-
"apollo-upload-client": "^18",
14-
"graphql": "^16",
15-
"next": "^14",
16-
"react": "^18",
17-
"react-dom": "^18"
12+
"@apollo/client": "^3.12.9",
13+
"apollo-upload-client": "^18.0.1",
14+
"graphql": "^16.10.0",
15+
"next": "^14.2.23",
16+
"react": "^18.3.1",
17+
"react-dom": "^18.3.1"
1818
},
1919
"devDependencies": {
20-
"@types/apollo-upload-client": "^17",
21-
"@types/node": "^20",
22-
"@types/react": "^18",
23-
"@types/react-dom": "^18",
24-
"autoprefixer": "^10",
25-
"eslint": "^8",
26-
"eslint-config-next": "14",
27-
"postcss": "^8",
28-
"tailwindcss": "^3",
29-
"typescript": "^5"
20+
"@types/apollo-upload-client": "^17.0.5",
21+
"@types/node": "^20.17.17",
22+
"@types/react": "^18.3.18",
23+
"@types/react-dom": "^18.3.5",
24+
"autoprefixer": "^10.4.20",
25+
"eslint": "^8.57.1",
26+
"eslint-config-next": "^14.2.23",
27+
"postcss": "^8.5.1",
28+
"tailwindcss": "^3.4.17",
29+
"typescript": "^5.7.3"
3030
}
3131
}

0 commit comments

Comments
 (0)