pdf-preview-error.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import PropTypes from 'prop-types'
  2. import { useTranslation, Trans } from 'react-i18next'
  3. import { memo, useCallback } from 'react'
  4. import { Button } from 'react-bootstrap'
  5. import PdfLogEntry from './pdf-log-entry'
  6. import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
  7. import { useStopOnFirstError } from '../../../shared/hooks/use-stop-on-first-error'
  8. import StopOnFirstErrorBadge from '../../../shared/components/stop-on-first-error-badge'
  9. import getMeta from '../../../utils/meta'
  10. function PdfPreviewError({ error }) {
  11. const { t } = useTranslation()
  12. switch (error) {
  13. case 'rendering-error':
  14. return (
  15. <ErrorLogEntry title={t('pdf_rendering_error')}>
  16. {t('something_went_wrong_rendering_pdf')}
  17. </ErrorLogEntry>
  18. )
  19. case 'clsi-maintenance':
  20. return (
  21. <ErrorLogEntry title={t('server_error')}>
  22. {t('clsi_maintenance')}
  23. </ErrorLogEntry>
  24. )
  25. case 'clsi-unavailable':
  26. return (
  27. <ErrorLogEntry title={t('server_error')}>
  28. {t('clsi_unavailable')}
  29. </ErrorLogEntry>
  30. )
  31. case 'too-recently-compiled':
  32. return (
  33. <ErrorLogEntry title={t('server_error')}>
  34. {t('too_recently_compiled')}
  35. </ErrorLogEntry>
  36. )
  37. case 'terminated':
  38. return (
  39. <ErrorLogEntry title={t('terminated')}>
  40. {t('compile_terminated_by_user')}
  41. </ErrorLogEntry>
  42. )
  43. case 'rate-limited':
  44. return (
  45. <ErrorLogEntry title={t('pdf_compile_rate_limit_hit')}>
  46. {t('project_flagged_too_many_compiles')}
  47. </ErrorLogEntry>
  48. )
  49. case 'compile-in-progress':
  50. return (
  51. <ErrorLogEntry title={t('pdf_compile_in_progress_error')}>
  52. {t('pdf_compile_try_again')}
  53. </ErrorLogEntry>
  54. )
  55. case 'auto-compile-disabled':
  56. return (
  57. <ErrorLogEntry title={t('autocompile_disabled')}>
  58. {t('autocompile_disabled_reason')}
  59. </ErrorLogEntry>
  60. )
  61. case 'project-too-large':
  62. return (
  63. <ErrorLogEntry title={t('project_too_large')}>
  64. {t('project_too_much_editable_text')}
  65. </ErrorLogEntry>
  66. )
  67. case 'timedout':
  68. return <TimedOutLogEntry />
  69. case 'failure':
  70. return (
  71. <ErrorLogEntry title={t('no_pdf_error_title')}>
  72. {t('no_pdf_error_explanation')}
  73. <ul className="log-entry-formatted-content-list">
  74. <li>{t('no_pdf_error_reason_unrecoverable_error')}</li>
  75. <li>
  76. <Trans
  77. i18nKey="no_pdf_error_reason_no_content"
  78. components={{ code: <code /> }}
  79. />
  80. </li>
  81. <li>
  82. <Trans
  83. i18nKey="no_pdf_error_reason_output_pdf_already_exists"
  84. components={{ code: <code /> }}
  85. />
  86. </li>
  87. </ul>
  88. </ErrorLogEntry>
  89. )
  90. case 'clear-cache':
  91. return (
  92. <ErrorLogEntry title={t('server_error')}>
  93. {t('somthing_went_wrong_compiling')}
  94. </ErrorLogEntry>
  95. )
  96. case 'pdf-viewer-loading-error':
  97. return (
  98. <ErrorLogEntry title={t('pdf_rendering_error')}>
  99. <Trans
  100. i18nKey="something_went_wrong_loading_pdf_viewer"
  101. components={[
  102. <strong key="strong-" />,
  103. // eslint-disable-next-line jsx-a11y/anchor-has-content
  104. <a
  105. key="learn-link"
  106. target="_blank"
  107. href="/learn/how-to/Resolving_access%2C_loading%2C_and_display_problems"
  108. />,
  109. // eslint-disable-next-line jsx-a11y/anchor-has-content
  110. <a key="contact-link" target="_blank" href="/contact" />,
  111. ]}
  112. />
  113. </ErrorLogEntry>
  114. )
  115. case 'validation-problems':
  116. return null // handled elsewhere
  117. case 'error':
  118. default:
  119. return (
  120. <ErrorLogEntry title={t('server_error')}>
  121. {t('somthing_went_wrong_compiling')}
  122. </ErrorLogEntry>
  123. )
  124. }
  125. }
  126. PdfPreviewError.propTypes = {
  127. error: PropTypes.string.isRequired,
  128. }
  129. export default memo(PdfPreviewError)
  130. function ErrorLogEntry({ title, headerIcon, children }) {
  131. const { t } = useTranslation()
  132. return (
  133. <PdfLogEntry
  134. headerTitle={title}
  135. headerIcon={headerIcon}
  136. formattedContent={children}
  137. entryAriaLabel={t('compile_error_entry_description')}
  138. level="error"
  139. />
  140. )
  141. }
  142. ErrorLogEntry.propTypes = {
  143. title: PropTypes.string.isRequired,
  144. headerIcon: PropTypes.element,
  145. children: PropTypes.any.isRequired,
  146. }
  147. function TimedOutLogEntry() {
  148. const { t } = useTranslation()
  149. const { enableStopOnFirstError } = useStopOnFirstError({
  150. eventSource: 'timeout',
  151. })
  152. const { startCompile, lastCompileOptions, setAnimateCompileDropdownArrow } =
  153. useCompileContext()
  154. const showStopOnFirstError = getMeta('ol-showStopOnFirstError')
  155. const handleEnableStopOnFirstErrorClick = useCallback(() => {
  156. enableStopOnFirstError()
  157. startCompile({ stopOnFirstError: true })
  158. setAnimateCompileDropdownArrow(true)
  159. }, [enableStopOnFirstError, startCompile, setAnimateCompileDropdownArrow])
  160. if (showStopOnFirstError) {
  161. return (
  162. <ErrorLogEntry title={t('timedout')}>
  163. <p>{t('project_timed_out_intro')}</p>
  164. <ul>
  165. <li>
  166. <Trans
  167. i18nKey="project_timed_out_optimize_images"
  168. components={[
  169. // eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key
  170. <a href="https://www.overleaf.com/learn/how-to/Optimising_very_large_image_files" />,
  171. ]}
  172. />
  173. </li>
  174. <li>
  175. <Trans
  176. i18nKey="project_timed_out_fatal_error"
  177. components={[
  178. // eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key
  179. <a href="https://www.overleaf.com/learn/how-to/Why_do_I_keep_getting_the_compile_timeout_error_message%3F#Fatal_compile_errors_blocking_the_compilation" />,
  180. ]}
  181. />
  182. {!lastCompileOptions.stopOnFirstError && (
  183. <>
  184. {' '}
  185. <Trans
  186. i18nKey="project_timed_out_enable_stop_on_first_error"
  187. components={[
  188. // eslint-disable-next-line react/jsx-key
  189. <Button
  190. bsSize="xs"
  191. bsStyle="info"
  192. onClick={handleEnableStopOnFirstErrorClick}
  193. />,
  194. ]}
  195. />{' '}
  196. <StopOnFirstErrorBadge placement="bottom" />
  197. </>
  198. )}
  199. </li>
  200. </ul>
  201. <p>
  202. <Trans
  203. i18nKey="project_timed_out_learn_more"
  204. components={{
  205. link: (
  206. // eslint-disable-next-line jsx-a11y/anchor-has-content
  207. <a href="https://www.overleaf.com/learn/how-to/Why_do_I_keep_getting_the_compile_timeout_error_message%3F" />
  208. ),
  209. }}
  210. />
  211. </p>
  212. </ErrorLogEntry>
  213. )
  214. } else {
  215. return (
  216. <ErrorLogEntry title={t('timedout')}>
  217. {t('proj_timed_out_reason')}
  218. <div>
  219. <a
  220. href="https://www.overleaf.com/learn/how-to/Why_do_I_keep_getting_the_compile_timeout_error_message%3F"
  221. target="_blank"
  222. rel="noopener"
  223. >
  224. {t('learn_how_to_make_documents_compile_quickly')}
  225. </a>
  226. </div>
  227. </ErrorLogEntry>
  228. )
  229. }
  230. }
  231. TimedOutLogEntry.propTypes = {}