Skip to content

Commit

Permalink
Fix: Non-writable pages/_app breaks build (#24849)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
darshkpatel and kodiakhq[bot] authored May 10, 2021
1 parent 8682705 commit 9e87596
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ export function getPageHandler(ctx: ServerlessHandlerCtx) {

if (err.code === 'ENOENT') {
res.statusCode = 404
} else if (err.code === 'DECODE_FAILED') {
} else if (err.code === 'DECODE_FAILED' || err.code === 'ENAMETOOLONG') {
// TODO: better error?
res.statusCode = 400
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ export default class Server {
return
}
} catch (err) {
if (err.code === 'DECODE_FAILED') {
if (err.code === 'DECODE_FAILED' || err.code === 'ENAMETOOLONG') {
res.statusCode = 400
return this.renderError(null, req, res, '/_error', {})
}
Expand Down
6 changes: 3 additions & 3 deletions packages/next/server/lib/find-page-file.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { join, sep as pathSeparator, normalize } from 'path'
import chalk from 'chalk'
import { isWriteable } from '../../build/is-writeable'
import { warn } from '../../build/output/log'
import { promises } from 'fs'
import { denormalizePagePath } from '../../next-server/server/normalize-page-path'
import { fileExists } from '../../lib/file-exists'

async function isTrueCasePagePath(pagePath: string, pagesDir: string) {
const pageSegments = normalize(pagePath).split(pathSeparator).filter(Boolean)
Expand Down Expand Up @@ -31,14 +31,14 @@ export async function findPageFile(
const relativePagePath = `${page}.${extension}`
const pagePath = join(rootDir, relativePagePath)

if (await isWriteable(pagePath)) {
if (await fileExists(pagePath)) {
foundPagePaths.push(relativePagePath)
}
}

const relativePagePathWithIndex = join(page, `index.${extension}`)
const pagePathWithIndex = join(rootDir, relativePagePathWithIndex)
if (await isWriteable(pagePathWithIndex)) {
if (await fileExists(pagePathWithIndex)) {
foundPagePaths.push(relativePagePathWithIndex)
}
}
Expand Down

0 comments on commit 9e87596

Please sign in to comment.