Server error when cancelling sales invoice

ERPNext v13.17.0 (and before updating, I think it was 13.15.0)
I have a sales invoice that cannot be cancelled with this error
FileNotFoundError: [Errno 2] No such file or directory: 'apps/erpnext/erpnext/healthcare/doctype/consultation'

Is there a way to fix? Which error log should I provide to help diagnose why?

This is a production site, but used to test some features/domains before. Currently it is on service domain only, no healthcare nor manufacturing nor other domains.

share the entire error , from the logs page. you need to find out why canceling an invoice is related to healthcare doctype consultation

Opening /app/error-log
there are 4 logs, but all are 1 months ago.

tail frappe-bench/logs/* -f when cancelling it on form view result in this:

==> logs/frappe.log <==
2022-01-05 10:15:46,067 ERROR frappe Could not take error snapshot: characters_written
Site: mti.mymetala.com
Form Dict: {'doctype': 'Sales Invoice', 'name': 'SINV-01757', 'cmd': 'frappe.desk.form.linked_with.get_submitted_linked_docs'}
Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 68, in application
    response = frappe.api.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/api.py", line 55, in handle
    return frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 31, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 67, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1208, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/linked_with.py", line 43, in get_submitted_linked_docs
    linked_docs = get_linked_docs(doctype, name, linkinfo)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/linked_with.py", line 170, in get_linked_docs
    link_meta_bundle = frappe.desk.form.load.get_meta_bundle(dt)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/load.py", line 81, in get_meta_bundle
    bundle = [frappe.desk.form.meta.get_meta(doctype)]
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/meta.py", line 26, in get_meta
    meta = FormMeta(doctype)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/meta.py", line 39, in __init__
    self.load_assets()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/meta.py", line 49, in load_assets
    self.add_code()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/meta.py", line 107, in add_code
    self.add_html_templates(path)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/meta.py", line 120, in add_html_templates
    for fname in os.listdir(path):
FileNotFoundError: [Errno 2] No such file or directory: '/home/frappe/frappe-bench/apps/erpnext/erpnext/healthcare/doctype/consultation'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/error.py", line 36, in make_error_snapshot
    snapshot = get_snapshot(exception)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/error.py", line 127, in get_snapshot
    value = pydoc.text.repr(getattr(evalue, name))
AttributeError: characters_written

It can be cancelled on list view. But it is linked to a journal entry related for advance payment need to be cancelled. Here is what happened if I cancel the journal entry from the form view:

==> logs/frappe.log <==
2022-01-05 10:17:44,451 ERROR frappe Could not take error snapshot: characters_written
Site: mti.mymetala.com
Form Dict: {'doctype': 'Journal Entry', 'name': 'JV-03846-3', 'cmd': 'frappe.desk.form.linked_with.get_submitted_linked_docs'}
Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 68, in application
    response = frappe.api.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/api.py", line 55, in handle
    return frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 31, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 67, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1208, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/linked_with.py", line 62, in get_submitted_linked_docs
    links = get_submitted_linked_docs(link_doctype, link.name, docs, visited)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/linked_with.py", line 43, in get_submitted_linked_docs
    linked_docs = get_linked_docs(doctype, name, linkinfo)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/linked_with.py", line 170, in get_linked_docs
    link_meta_bundle = frappe.desk.form.load.get_meta_bundle(dt)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/load.py", line 81, in get_meta_bundle
    bundle = [frappe.desk.form.meta.get_meta(doctype)]
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/meta.py", line 26, in get_meta
    meta = FormMeta(doctype)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/meta.py", line 39, in __init__
    self.load_assets()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/meta.py", line 49, in load_assets
    self.add_code()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/meta.py", line 107, in add_code
    self.add_html_templates(path)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/meta.py", line 120, in add_html_templates
    for fname in os.listdir(path):
FileNotFoundError: [Errno 2] No such file or directory: '/home/frappe/frappe-bench/apps/erpnext/erpnext/healthcare/doctype/consultation'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/error.py", line 36, in make_error_snapshot
    snapshot = get_snapshot(exception)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/error.py", line 127, in get_snapshot
    value = pydoc.text.repr(getattr(evalue, name))
AttributeError: characters_written

Both invoice and journal entry can be cancelled from list view with no error log generated.

I got this error log after restoring the VPS to before I cancelled it from list view. I don’t think I can do that again.