Skip to content

Commit

Permalink
🐛 Handle when config.env.gameVersion is undefined (#1668)
Browse files Browse the repository at this point in the history
  • Loading branch information
misode authored Dec 10, 2024
1 parent 0565b6c commit 28a9d70
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/java-edition/src/dependency/mcmeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function resolveConfiguredVersion(
versions: McmetaVersions,
packMcmeta: PackMcmeta | undefined,
packType: 'assets' | 'data' | undefined,
logger: core.Logger,
): VersionInfo {
function findReleaseTarget(version: McmetaVersion): string {
if (version.release_target) {
Expand Down Expand Up @@ -49,7 +50,14 @@ export function resolveConfiguredVersion(
throw new Error('mcmeta version list is empty')
}

// This should never happen, but for some reason happens sometimes
// https://github.com/SpyglassMC/Spyglass/issues/1621
if (inputVersion === undefined) {
logger.warn('[resolveConfiguredVersion] Input version was undefined! Falling back to "auto"')
inputVersion = 'auto'
}
inputVersion = inputVersion.toLowerCase()

versions = versions.sort((a, b) => b.data_version - a.data_version)
const latestRelease = versions.find((v) => v.type === 'release')
if (inputVersion === 'auto') {
Expand Down
3 changes: 2 additions & 1 deletion packages/java-edition/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const initialize: core.ProjectInitializer = async (ctx) => {
versions,
packMcmeta,
type,
logger,
)
packs.push({ type, packRoot, packMcmeta, versionInfo })
}
Expand All @@ -87,7 +88,7 @@ export const initialize: core.ProjectInitializer = async (ctx) => {
const pack = packs.find(p => p.packMcmeta !== undefined && p.type === 'data')
?? packs.find(p => p.packMcmeta !== undefined && p.type === 'assets')
const version = pack === undefined
? resolveConfiguredVersion(config.env.gameVersion, versions, undefined, undefined)
? resolveConfiguredVersion(config.env.gameVersion, versions, undefined, undefined, logger)
: pack.versionInfo
const packMessage = pack === undefined
? 'Failed finding a valid pack.mcmeta'
Expand Down
1 change: 1 addition & 0 deletions packages/java-edition/test/dependency/mcmeta.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('mcmeta', () => {
Fixtures.Versions,
packMcmeta,
undefined,
console,
)
snapshot(actual)
})
Expand Down

0 comments on commit 28a9d70

Please sign in to comment.