Could not create resource file resources.txt: incompatible character encodings

11 views
Skip to first unread message

Angel L. Mateo

unread,
Nov 18, 2016, 2:18:08 PM11/18/16
to puppet...@googlegroups.com
Hello,

I'm programming my own custom type. It is at
https://github.com/amateo/puppet-omd/blob/feature/TLM-4087/lib/puppet/type/thruk_bp.rb
and is mainly copied from concat provided in puppetlabs/concat.

My problem with this type is that it creates a file from a json and
some parameters must support UTF-8 characters. With the implementation I
have, if I use UTF-8 in some field, I get an error in the call
JSON.pretty_generate(json):

Error: /Stage[main]/Main/Thruk_bp[atica/Autenticación de usuarios]:
Failed to generate additional resources using 'eval_generate': "\xC3"
from ASCII-8BIT to UTF-8

So I have forced all my params to be coded in UTF-8 using a
force_encoding call. What I do is to inherit from NagiosParam in all
parameters definition, where NagiosParam is:

class NagiosParam < Puppet::Property
class << self
attr_accessor :boundaries, :default
end

def should
if @should and @should[0] == :absent
:absent
else
@should.join(',')
end
end

munge do |value|
if value == 'absent' or value == :absent
return :absent
elsif value == ''
return :absent
else
if value.respond_to?('force_encoding') then
value.force_encoding('ASCII-8BIT')
end
return super(value)
end
end
end

In this case, all resources are created without any problem, but I get
the error

Error: Could not create resource file
/opt/puppetlabs/puppet/cache/state/resources.txt: incompatible character
encodings: ASCII-8BIT and UTF-8

in every agent run.

What is the correct way to handle with different language encodings?

--
Angel L. Mateo Martínez
Sección de Telemática
Área de Tecnologías de la Información
y las Comunicaciones Aplicadas (ATICA)
http://www.um.es/atica
Tfo: 868889150
Fax: 868888337
Reply all
Reply to author
Forward
0 new messages