Unverified Commit 626955d6 authored by Balázs Orbán's avatar Balázs Orbán Committed by GitHub

fix: ensure revalidation error is logged from response-cache (#32657)

Something [between `11.0.2-canary.5` and `11.0.2-canary.6`](https://github.com/vercel/next.js/compare/v11.0.2-canary.5...v11.0.2-canary.6) changed the behavior that logged any runtime errors in `getStaticProps` to stderr. This is only observable if `getStaticProps` has a `revalidate` value, and the build did not fail. The error has to happen in a subsequent revalidation step.


This PR reverts the change and fixes #30375.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
Co-authored-by: 's avatarJJ Kasper <22380829+ijjk@users.noreply.github.com>
parent 2efc944c
...@@ -107,7 +107,13 @@ export default class ResponseCache { ...@@ -107,7 +107,13 @@ export default class ResponseCache {
) )
} }
} catch (err) { } catch (err) {
rejecter(err as Error) // while revalidating in the background we can't reject as
// we already resolved the cache entry so log the error here
if (resolved) {
console.error(err)
} else {
rejecter(err as Error)
}
} finally { } finally {
if (key) { if (key) {
this.pendingResponses.delete(key) this.pendingResponses.delete(key)
......
...@@ -7,12 +7,15 @@ import { ...@@ -7,12 +7,15 @@ import {
launchApp, launchApp,
nextBuild, nextBuild,
renderViaHTTP, renderViaHTTP,
nextStart,
check,
} from 'next-test-utils' } from 'next-test-utils'
import { join } from 'path' import { join } from 'path'
import { import {
GSP_NO_RETURNED_VALUE, GSP_NO_RETURNED_VALUE,
GSSP_NO_RETURNED_VALUE, GSSP_NO_RETURNED_VALUE,
} from '../../../../packages/next/dist/lib/constants' } from '../../../../packages/next/dist/lib/constants'
import { PHASE_PRODUCTION_BUILD } from '../../../../packages/next/shared/lib/constants'
const appDir = join(__dirname, '..') const appDir = join(__dirname, '..')
const indexPage = join(appDir, 'pages/index.js') const indexPage = join(appDir, 'pages/index.js')
...@@ -130,7 +133,49 @@ describe('GS(S)P Page Errors', () => { ...@@ -130,7 +133,49 @@ describe('GS(S)P Page Errors', () => {
runTests(true) runTests(true)
}) })
describe('production mode', () => { describe('build mode', () => {
runTests() runTests()
}) })
describe('start mode', () => {
it('Error stack printed to stderr', async () => {
try {
await fs.writeFile(
indexPage,
`export default function Page() {
return <div/>
}
export function getStaticProps() {
// Make it pass on the build phase
if(process.env.NEXT_PHASE === "${PHASE_PRODUCTION_BUILD}") {
return { props: { foo: 'bar' }, revalidate: 1 }
}
throw new Error("Oops")
}
`
)
await nextBuild(appDir)
appPort = await findPort()
let stderr = ''
app = await nextStart(appDir, appPort, {
onStderr: (msg) => {
stderr += msg || ''
},
})
await check(async () => {
await renderViaHTTP(appPort, '/')
return stderr
}, /error: oops/i)
expect(stderr).toContain('Error: Oops')
expect(stderr).toContain(`\n at getStaticProps`)
} finally {
await killApp(app)
}
})
})
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment