Code Monkey home page Code Monkey logo

ass_ole's Issues

AssOle::Runtimes::RuntimeDispatcher#ole_runtime_get

Instance of class returns self.class but must returns Runtime like this:

def ole_runtime_get
  if self.class == Module
    instance_variable_get(:@ole_runtime)
  elsif self.class == Class
    class_variable_get(:@@ole_runtime)
  else
    self.class.send :ole_runtime_get
  end
end

Incompatible character encodings: ASCII-8BIT and UTF-8 for errors raised in WIN32OLE

Сообщение об ошибке возникшей на стороне OLE сервера 1С, которое содержит текст на русском языке, имеет не ASCII символы в разной кодировке. Причина в том, что текст исключения который формируется в 1С имеет кодировку UTF-8 к которому Windows добавляет текст в кодировке локали (в моём случае Windows-XP в кодировке cp1251) вида:

    HRESULT error code:0x80020009
      Ошибка.

Это приводит к ошибкам тип Encoding::CompatibilityError при попытке обработать (проанализировать) сообщение об ошибке.

Пример исключения в обработчике ПередЗаписью элемента справочника:

begin
  person = make_person
rescue Exeption => e
  e.class #=> WIN32OLERuntimeError
  e.message.encoding #=> #<Encoding:ASCII-8BIT>
  e.message #=> "(in OLE method `Write': )\n    OLE error code:1001 in 1C:Enterprise 8.3.10.2561\n      \xD0\x9D\xD0\xB5 \xD1\x83\xD0\xB4\xD0\xB0\xD0\xBB\xD0\xBE\xD1\x81\xD1\x8C \xD0\xB7\xD0\xB0\xD0\xBF\xD0\xB8\xD1\x81\xD0\xB0\xD1\x82\xD1\x8C \"fake person 906915424  (Persons)\"!\n    HRESULT error code:0x80020009\n      \xCE\xF8\xE8\xE1\xEA\xE0."
  e.message + 'не ASCII текст' #Ошибка Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8
end

Аналогично обстоят дела если вызвать несуществующий метод OLE объекта имеющий не ASCII имя:

begin
  ole_connector.ЭтогоМетодаНет
rescue Exception => e
  e.class #=> NoMethodError
  e.message.encoding #=> #<Encoding:ASCII-8BIT>
  e.message #=> "unknown property or method: `\xD0\xAD\xD1\x82\xD0\xBE\xD0\xB3\xD0\xBE\xD0\x9C\xD0\xB5\xD1\x82\xD0\xBE\xD0\xB4\xD0\xB0\xD0\x9D\xD0\xB5\xD1\x82'\n    HRESULT error code:0x80020006\n      \xCD\xE5\xE8\xE7\xE2\xE5\xF1\xF2\xED\xEE\xE5 \xE8\xEC\xFF."
  e.message + 'не ASCII текст' #Ошибка Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8  
end

Решение

Данная проблема была решена в проекте ass_tests для частного случая (разработка тестов) как Monkey патчи классов исключений.

В процессе эксплуатации ass_ole стало понятно, что данные патчи неплохо иметь для всего ass_ole стека в том числе и для ass_tests.

Посему необходимо выделить из проекта ass_tests и применить в данном проекте.

Результат здесь: Monkey патчи.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.