Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ATA: Call delegate.errorMessage upon Errors #3311

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-bulldogs-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@typescript/ata": patch
---

Added calls to delegate.errorMessage() on errors
32 changes: 26 additions & 6 deletions packages/ata/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ export const setupTypeAcquisition = (config: ATABootstrapConfig) => {

// Grab the module trees which gives us a list of files to download
const trees = await Promise.all(depsToGet.map(f => getFileTreeForModuleWithTag(config, f.module, f.version)))
const treesOnly = trees.filter(t => !("error" in t)) as NPMTreeMeta[]
const treesOnly: NPMTreeMeta[] = []

trees.forEach(t => {
if ("error" in t) {
config.delegate.errorMessage?.(t.userFacingMessage, t.error)
} else {
treesOnly.push(t)
}
})

// These are the modules which we can grab directly
const hasDTS = treesOnly.filter(t => t.files.find(f => isDtsFile(f.name)))
Expand All @@ -81,7 +89,16 @@ export const setupTypeAcquisition = (config: ATABootstrapConfig) => {
mightBeOnDT.map(f => getFileTreeForModuleWithTag(config, `@types/${getDTName(f.moduleName)}`, "latest"))
)

const dtTreesOnly = dtTrees.filter(t => !("error" in t)) as NPMTreeMeta[]
const dtTreesOnly: NPMTreeMeta[] = []

dtTrees.forEach(t => {
if ("error" in t) {
config.delegate.errorMessage?.(t.userFacingMessage, t.error)
} else {
dtTreesOnly.push(t)
}
})

const dtsFilesFromDT = dtTreesOnly.map(t => treeToDTSFiles(t, `/node_modules/@types/${getDTName(t.moduleName).replace("types__", "")}`))

// Collect all the npm and DT DTS requests and flatten their arrays
Expand All @@ -102,7 +119,9 @@ export const setupTypeAcquisition = (config: ATABootstrapConfig) => {
fsMap.set(path, pkgJSON)
config.delegate.receivedFile?.(pkgJSON, path)
} else {
config.logger?.error(`Could not download package.json for ${tree.moduleName}`)
const userFacingMessage = `Could not download package.json for ${tree.moduleName}`
config.logger?.error(userFacingMessage)
config.delegate.errorMessage?.(userFacingMessage, pkgJSON)
}
}

Expand All @@ -112,8 +131,9 @@ export const setupTypeAcquisition = (config: ATABootstrapConfig) => {
const dtsCode = await getDTSFileForModuleWithVersion(config, dts.moduleName, dts.moduleVersion, dts.path)
estimatedDownloaded++
if (dtsCode instanceof Error) {
// TODO?
config.logger?.error(`Had an issue getting ${dts.path} for ${dts.moduleName}`)
const userFacingMessage = `Had an issue getting ${dts.path} for ${dts.moduleName}`
config.logger?.error(userFacingMessage)
config.delegate.errorMessage?.(userFacingMessage, dtsCode)
} else {
fsMap.set(dts.vfsPath, dtsCode)
config.delegate.receivedFile?.(dtsCode, dts.vfsPath)
Expand Down Expand Up @@ -226,7 +246,7 @@ export const getFileTreeForModuleWithTag = async (
const versions = await getNPMVersionsForModule(config, moduleName)
if (versions instanceof Error) {
return {
error: response,
error: versions,
userFacingMessage: `Could not get versions on npm for ${moduleName} - possible typo?`,
}
}
Expand Down