# 사용자 설정 저장 시 500 오류가 발생하는 원인은 무엇일까요?

**URL:** https://meta.discourse.org/t/what-could-be-causing-500-errors-when-saving-user-preferences/273790
**Category:** Support
**Created:** [8월 3, 2023, 9:44오전 UTC](https://meta.discourse.org/t/what-could-be-causing-500-errors-when-saving-user-preferences/273790 "2023-08-03T09:44:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tkrunning](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tkrunning/32/119481_2.png) [@tkrunning](https://meta.discourse.org/u/tkrunning)
#### Post date: [8월 3, 2023, 9:44오전 UTC](https://meta.discourse.org/t/what-could-be-causing-500-errors-when-saving-user-preferences/273790/1 "2023-08-03T09:44:02Z")

</div>

지난 며칠간 내 Discourse 인스턴스에서 또 다른 기이한 버그를 발견했습니다. 제 관리자 계정의 사용자 설정을 저장할 수 없으며, 500 오류만 발생합니다. `u/[MY_USERNAME].json`에 대한 모든 `PUT` 요청에서도 동일한 문제가 발생하는 것 같습니다.

 ![CleanShot 2023-08-03 at 11.30.46@2x](https://global.discourse-cdn.com/meta/original/4X/c/d/5/cd5df29ca12919499336e5b9dd9faeb325c6c605.png)

유효한 API 키를 사용하여 Postman에서 동일한 요청을 반복해 보았지만, 이 역시 실패했습니다:

 ![Request body (copied as cURL from Safari)](https://global.discourse-cdn.com/meta/original/4X/0/8/7/08789e4c789470301c082553d2c2b5e8d63b8c3b.png)

 ![Response](https://global.discourse-cdn.com/meta/original/4X/4/2/c/42cb3f9ee86312fd5961aa78eac62d52ca8a128d.png)

/logs에서도 오류가 표시되지 않습니다.

다른 사용자 계정은 영향을 받지 않는 것 같습니다. 적어도 제가 테스트해 본 계정은 그렇습니다.

어제 Discourse를 최신 버전으로 업그레이드했지만, 업그레이드 이전에도 이 문제가 존재했습니다.

이 문제를 디버깅하기 위해 계속 진행할 수 있는 방법에 대한 아이디어가 있을까요?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [8월 3, 2023, 10:05오전 UTC](https://meta.discourse.org/t/what-could-be-causing-500-errors-when-saving-user-preferences/273790/2 "2023-08-03T10:05:48Z")

</div>

관리자로 로그인한 상태에서 Discourse 인스턴스의 `/logs` 페이지를 방문하면, 이러한 유형의 오류에 대한 더 자세한 정보를 확인할 수 있습니다. 해당 오류에 대한 'info’와 ‘backtrace’ 탭의 내용을 공유해 주시면 문제를 파악하는 데 도움이 됩니다.

수정: 이미 해당 페이지를 확인하셨네요 🤔. `/logs` 페이지 왼쪽 하단에 모든 오류 유형이 활성화되어 있는지 한 번 더 확인해 주시겠어요?

---

<div class="post-metadata">

### Author: ![tkrunning](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tkrunning/32/119481_2.png) [@tkrunning](https://meta.discourse.org/u/tkrunning)
#### Post date: [8월 3, 2023, 10:24오전 UTC](https://meta.discourse.org/t/what-could-be-causing-500-errors-when-saving-user-preferences/273790/3 "2023-08-03T10:24:02Z")

</div>

아마도 실제로 이 오류였을 것 같습니다:

 ![CleanShot 2023-08-03 at 12.17.58@2x](https://global.discourse-cdn.com/meta/original/4X/a/6/8/a68b54f5ada5e5c200e11ba6a83b245b2db76896.png)

이것은 다음 문제 때문에 나타나는 것만이라고 생각했습니다:

> [@Safari에서 Composer 미리보기가 작동하지 않음](https://meta.discourse.org/t/composer-previews-not-working-in-safari/273717/7):
>
> Now only one error showed up, but here it is expanded: However, that might be a good hint, as I also ran into this Safari issue when [adding in a regex with negative lookbehind recently](https://meta.discourse.org/t/negative-lookbehind-not-working-in-watched-words-regex/271981/6). My Safari is at 16.3. I’ll try upgrading it to 16.6 and see if that solves it. EDIT: I see that negative lookbehinds are [only supported from 16.4](https://caniuse.com/js-regexp-lookbehind), so the update should be likely to fix my previous issue—let’s see if this issue is related. However, I’m a bit concerned tha…

하지만 결국 모든 것이 관련이 있었습니다.

전체 로그는 다음과 같습니다:

정보:

```plaintext
RegexpError (invalid pattern in look-behind: /((?<!estonia.*\s)\be-residence\b(?!.*estonia))/i)
app/services/word_watcher.rb:264:in `initialize'
app/services/word_watcher.rb:264:in `new'
app/services/word_watcher.rb:264:in `block in replace'
app/services/word_watcher.rb:262:in `each'
app/services/word_watcher.rb:262:in `reduce'
app/services/word_watcher.rb:262:in `replace'
app/services/word_watcher.rb:149:in `replace_link'
app/services/word_watcher.rb:155:in `apply_to_text'
app/models/user_profile.rb:194:in `apply_watched_words'
app/services/user_updater.rb:242:in `block in update'
app/services/user_updater.rb:197:in `update'
app/controllers/users_controller.rb:250:in `block in update'
app/controllers/application_controller.rb:748:in `json_result'
app/controllers/users_controller.rb:244:in `update'
app/controllers/application_controller.rb:420:in `block in with_resolved_locale'
app/controllers/application_controller.rb:420:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:74:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:389:in `call'
lib/middleware/gtm_script_nonce_injector.rb:10:in `call'
config/initializers/008-rack-cors.rb:24:in `call'
config/initializers/100-quiet_logger.rb:20:in `call'
config/initializers/100-silence_logger.rb:29:in `call'
lib/middleware/enforce_hostname.rb:24:in `call'
lib/middleware/request_tracker.rb:233:in `call'

```

백트레이스:

```plaintext
app/services/word_watcher.rb:264:in `initialize'
app/services/word_watcher.rb:264:in `new'
app/services/word_watcher.rb:264:in `block in replace'
app/services/word_watcher.rb:262:in `each'
app/services/word_watcher.rb:262:in `reduce'
app/services/word_watcher.rb:262:in `replace'
app/services/word_watcher.rb:149:in `replace_link'
app/services/word_watcher.rb:155:in `apply_to_text'
app/models/user_profile.rb:194:in `apply_watched_words'
activesupport (7.0.5.1) lib/active_support/callbacks.rb:400:in `block in make_lambda'
activesupport (7.0.5.1) lib/active_support/callbacks.rb:180:in `block (2 levels) in halting_and_conditional'
activesupport (7.0.5.1) lib/active_support/callbacks.rb:687:in `block (2 levels) in default_terminator'
activesupport (7.0.5.1) lib/active_support/callbacks.rb:686:in `catch'
activesupport (7.0.5.1) lib/active_support/callbacks.rb:686:in `block in default_terminator'
activesupport (7.0.5.1) lib/active_support/callbacks.rb:181:in `block in halting_and_conditional'
activesupport (7.0.5.1) lib/active_support/callbacks.rb:595:in `block in invoke_before'
activesupport (7.0.5.1) lib/active_support/callbacks.rb:595:in `each'
activesupport (7.0.5.1) lib/active_support/callbacks.rb:595:in `invoke_before'
activesupport (7.0.5.1) lib/active_support/callbacks.rb:116:in `block in run_callbacks'
activerecord (7.0.5.1) lib/active_record/autosave_association.rb:370:in `around_save_collection_association'
activesupport (7.0.5.1) lib/active_support/callbacks.rb:127:in `block in run_callbacks'
activesupport (7.0.5.1) lib/active_support/callbacks.rb:138:in `run_callbacks'
activesupport (7.0.5.1) lib/active_support/callbacks.rb:929:in `_run_save_callbacks'
activerecord (7.0.5.1) lib/active_record/callbacks.rb:455:in `create_or_update'
activerecord (7.0.5.1) lib/active_record/timestamp.rb:126:in `create_or_update'
activerecord (7.0.5.1) lib/active_record/persistence.rb:615:in `save'
activerecord (7.0.5.1) lib/active_record/validations.rb:47:in `save'
activerecord (7.0.5.1) lib/active_record/transactions.rb:298:in `block in save'
activerecord (7.0.5.1) lib/active_record/transactions.rb:354:in `block in with_transaction_returning_status'
activerecord (7.0.5.1) lib/active_record/connection_adapters/abstract/database_statements.rb:314:in `transaction'
activerecord (7.0.5.1) lib/active_record/transactions.rb:350:in `with_transaction_returning_status'
activerecord (7.0.5.1) lib/active_record/transactions.rb:298:in `save'
activerecord (7.0.5.1) lib/active_record/suppressor.rb:50:in `save'
app/services/user_updater.rb:242:in `block in update'
activerecord (7.0.5.1) lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
activesupport (7.0.5.1) lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
activesupport (7.0.5.1) lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
activesupport (7.0.5.1) lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
activesupport (7.0.5.1) lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
activerecord (7.0.5.1) lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
activerecord (7.0.5.1) lib/active_record/connection_adapters/abstract/database_statements.rb:316:in `transaction'
activerecord (7.0.5.1) lib/active_record/transactions.rb:209:in `transaction'
app/services/user_updater.rb:197:in `update'
app/controllers/users_controller.rb:250:in `block in update'
app/controllers/application_controller.rb:748:in `json_result'
app/controllers/users_controller.rb:244:in `update'
actionpack (7.0.5.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (7.0.5.1) lib/abstract_controller/base.rb:215:in `process_action'
actionpack (7.0.5.1) lib/action_controller/metal/rendering.rb:165:in `process_action'
actionpack (7.0.5.1) lib/abstract_controller/callbacks.rb:234:in `block in process_action'
activesupport (7.0.5.1) lib/active_support/callbacks.rb:118:in `block in run_callbacks'
app/controllers/application_controller.rb:420:in `block in with_resolved_locale'
i18n (1.14.1) lib/i18n.rb:322:in `with_locale'
app/controllers/application_controller.rb:420:in `with_resolved_locale'
activesupport (7.0.5.1) lib/active_support/callbacks.rb:127:in `block in run_callbacks'
activesupport (7.0.5.1) lib/active_support/callbacks.rb:138:in `run_callbacks'
actionpack (7.0.5.1) lib/abstract_controller/callbacks.rb:233:in `process_action'
actionpack (7.0.5.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (7.0.5.1) lib/action_controller/metal/instrumentation.rb:67:in `block in process_action'
activesupport (7.0.5.1) lib/active_support/notifications.rb:206:in `block in instrument'
activesupport (7.0.5.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (7.0.5.1) lib/active_support/notifications.rb:206:in `instrument'
actionpack (7.0.5.1) lib/action_controller/metal/instrumentation.rb:66:in `process_action'
actionpack (7.0.5.1) lib/action_controller/metal/params_wrapper.rb:259:in `process_action'
activerecord (7.0.5.1) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
actionpack (7.0.5.1) lib/abstract_controller/base.rb:151:in `process'
actionview (7.0.5.1) lib/action_view/rendering.rb:39:in `process'
rack-mini-profiler (3.1.1) lib/mini_profiler/profiling_methods.rb:111:in `block in profile_method'  
actionpack (7.0.5.1) lib/action_controller/metal.rb:188:in `dispatch'
actionpack (7.0.5.1) lib/action_controller/metal.rb:251:in `dispatch'
actionpack (7.0.5.1) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
actionpack (7.0.5.1) lib/action_dispatch/routing/route_set.rb:32:in `serve'
actionpack (7.0.5.1) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (7.0.5.1) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (7.0.5.1) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (7.0.5.1) lib/action_dispatch/routing/route_set.rb:852:in `call'
lib/middleware/omniauth_bypass_middleware.rb:74:in `call'
rack (2.2.8) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.2.8) lib/rack/conditional_get.rb:40:in `call'
rack (2.2.8) lib/rack/head.rb:12:in `call'
actionpack (7.0.5.1) lib/action_dispatch/http/permissions_policy.rb:38:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:389:in `call'
lib/middleware/gtm_script_nonce_injector.rb:10:in `call'
config/initializers/008-rack-cors.rb:24:in `call'
rack (2.2.8) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.8) lib/rack/session/abstract/id.rb:260:in `call'
actionpack (7.0.5.1) lib/action_dispatch/middleware/cookies.rb:704:in `call'
actionpack (7.0.5.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (7.0.5.1) lib/active_support/callbacks.rb:99:in `run_callbacks'
actionpack (7.0.5.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (7.0.5.1) lib/action_dispatch/middleware/debug_exceptions.rb:28:in `call'
actionpack (7.0.5.1) lib/action_dispatch/middleware/show_exceptions.rb:26:in `call'
logster (2.12.2) lib/logster/middleware/reporter.rb:43:in `call'
railties (7.0.5.1) lib/rails/rack/logger.rb:40:in `call_app'
railties (7.0.5.1) lib/rails/rack/logger.rb:27:in `call'
config/initializers/100-quiet_logger.rb:20:in `call'
config/initializers/100-silence_logger.rb:29:in `call'
actionpack (7.0.5.1) lib/action_dispatch/middleware/remote_ip.rb:93:in `call'
actionpack (7.0.5.1) lib/action_dispatch/middleware/request_id.rb:26:in `call'
lib/middleware/enforce_hostname.rb:24:in `call'
rack (2.2.8) lib/rack/method_override.rb:24:in `call'
actionpack (7.0.5.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
rack (2.2.8) lib/rack/sendfile.rb:110:in `call'
actionpack (7.0.5.1) lib/action_dispatch/middleware/host_authorization.rb:131:in `call'
rack-mini-profiler (3.1.1) lib/mini_profiler.rb:413:in `call'
message_bus (4.3.7) lib/message_bus/rack/middleware.rb:60:in `call'
lib/middleware/request_tracker.rb:233:in `call'
railties (7.0.5.1) lib/rails/engine.rb:530:in `call'
railties (7.0.5.1) lib/rails/

```

감시 단어 \> 링크에서 정규식을 제거하면 문제가 해결됩니다. 하지만 이는 이 문제가 여전히 해결되지 않았음을 의미합니다:

> [@감시 단어 정규식에서 negative lookbehind가 작동하지 않음](https://meta.discourse.org/t/negative-lookbehind-not-working-in-watched-words-regex/271981/6):
>
> Interestingly, it seems to be browser-dependent. I get the error in Safari, but not in Chrome. When adding it in Chrome and viewing the list in Safari the error shows up there. But I guess I can just ignore it for now.

ECMA 2018 표준에 따르면 정규식이 유효하지만, Ruby의 정규식 표준에는 해당하지 않을 수도 있습니다.

 ![CleanShot 2023-08-03 at 12.41.59@2x](https://global.discourse-cdn.com/meta/original/4X/5/7/4/574a683f0e1e2f2e71b5355212a272a64c7fdf46.png)

이 정규식은 포럼의 게시물에서도 의도대로 작동합니다.
