code: def test_extract_errors() -> None:
      """
      Test that custom error messages are extracted correctly.
      """
      from superset.db_engine_specs.mssql import MssqlEngineSpec
  
      msg = dedent(
          """
  DB-Lib error message 20009, severity 9:
  Unable to connect: Adaptive Server is unavailable or does not exist (locahost)
          """
      )
      result = MssqlEngineSpec.extract_errors(Exception(msg))
      assert result == [
          SupersetError(
              error_type=SupersetErrorType.CONNECTION_INVALID_HOSTNAME_ERROR,
              message='The hostname "locahost" cannot be resolved.',
              level=ErrorLevel.ERROR,
              extra={
                  "engine_name": "Microsoft SQL Server",
                  "issue_codes": [
                      {
                          "code": 1007,
                          "message": "Issue 1007 - The hostname provided can't be resolved.",
                      }
                  ],
              },
          )
      ]
  
      msg = dedent(
          """
  DB-Lib error message 20009, severity 9:
  Unable to connect: Adaptive Server is unavailable or does not exist (localhost)
  Net-Lib error during Connection refused (61)
  DB-Lib error message 20009, severity 9:
  Unable to connect: Adaptive Server is unavailable or does not exist (localhost)
  Net-Lib error during Connection refused (61)
          """
      )
      result = MssqlEngineSpec.extract_errors(
          Exception(msg),
          context={"port": 12345, "hostname": "localhost"},
      )
      assert result == [
          SupersetError(
              error_type=SupersetErrorType.CONNECTION_PORT_CLOSED_ERROR,
              message='Port 12345 on hostname "localhost" refused the connection.',
              level=ErrorLevel.ERROR,
              extra={
                  "engine_name": "Microsoft SQL Server",
                  "issue_codes": [
                      {
                          "code": 1008,
                          "message": "Issue 1008 - The port is closed.",
                      }
                  ],
              },
          )
      ]
  
      msg = dedent(
          """
  DB-Lib error message 20009, severity 9:
  Unable to connect: Adaptive Server is unavailable or does not exist (example.com)
  Net-Lib error during Operation timed out (60)
  DB-Lib error message 20009, severity 9:
  Unable to connect: Adaptive Server is unavailable or does not exist (example.com)
  Net-Lib error during Operation timed out (60)
          """
      )
      result = MssqlEngineSpec.extract_errors(
          Exception(msg),
          context={"port": 12345, "hostname": "example.com"},
      )
      assert result == [
          SupersetError(
              error_type=SupersetErrorType.CONNECTION_HOST_DOWN_ERROR,
              message=(
                  'The host "example.com" might be down, '
                  "and can't be reached on port 12345."
              ),
              level=ErrorLevel.ERROR,
              extra={
                  "engine_name": "Microsoft SQL Server",
                  "issue_codes": [
                      {
                          "code": 1009,
                          "message": "Issue 1009 - The host might be down, and can't be reached on the provided port.",
                      }
                  ],
              },
          )
      ]
  
      msg = dedent(
          """
  DB-Lib error message 20009, severity 9:
  Unable to connect: Adaptive Server is unavailable or does not exist (93.184.216.34)
  Net-Lib error during Operation timed out (60)
  DB-Lib error message 20009, severity 9:
  Unable to connect: Adaptive Server is unavailable or does not exist (93.184.216.34)
  Net-Lib error during Operation timed out (60)
          """
      )
      result = MssqlEngineSpec.extract_errors(
          Exception(msg),
          context={"port": 12345, "hostname": "93.184.216.34"},
      )
      assert result == [
          SupersetError(
              error_type=SupersetErrorType.CONNECTION_HOST_DOWN_ERROR,
              message=(
                  'The host "93.184.216.34" might be down, '
                  "and can't be reached on port 12345."
              ),
              level=ErrorLevel.ERROR,
              extra={
                  "engine_name": "Microsoft SQL Server",
                  "issue_codes": [
                      {
                          "code": 1009,
                          "message": "Issue 1009 - The host might be down, and can't be reached on the provided port.",
                      }
                  ],
              },
          )
      ]
  
      msg = dedent(
          """
  DB-Lib error message 20018, severity 14:
  General SQL Server error: Check messages from the SQL Server
  DB-Lib error message 20002, severity 9:
  Adaptive Server connection failed (mssqldb.cxiotftzsypc.us-west-2.rds.amazonaws.com)
  DB-Lib error message 20002, severity 9:
  Adaptive Server connection failed (mssqldb.cxiotftzsypc.us-west-2.rds.amazonaws.com)
          """
      )
      result = MssqlEngineSpec.extract_errors(
          Exception(msg),
          context={"username": "testuser", "database": "testdb"},
      )
      assert result == [
          SupersetError(
              message='Either the username "testuser", password, or database name "testdb" is incorrect.',
              error_type=SupersetErrorType.CONNECTION_ACCESS_DENIED_ERROR,
              level=ErrorLevel.ERROR,
              extra={
                  "engine_name": "Microsoft SQL Server",
                  "issue_codes": [
                      {
                          "code": 1014,
                          "message": "Issue 1014 - Either the username or "
                          "the password is wrong.",
                      },
                      {
                          "code": 1015,
                          "message": "Issue 1015 - Either the database is "
                          "spelled incorrectly or does not exist.",
                      },
                  ],
              },
          )
      ]
  
imports: import unittest.mock
  from datetime import datetime
  from textwrap import dedent
  from typing import Any, Optional
  import pytest
  from sqlalchemy import column, table
  from sqlalchemy.dialects import mssql
  from sqlalchemy.dialects.mssql import DATE, NTEXT, NVARCHAR, TEXT, VARCHAR
  from sqlalchemy.sql import select
  from sqlalchemy.types import String, TypeEngine, UnicodeText
  from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
  from superset.utils.core import GenericDataType
  from tests.unit_tests.db_engine_specs.utils import assert_column_spec, assert_convert_dttm
  from tests.unit_tests.fixtures.common import dttm
label_desc: Use image node_id 11 for calling a global function with example usage: test_extract_errors() without return types